(defrule display_Pap_en_Vleis
(answerc1 ?answPV)
(test (integerp ?answPV))
(test (= ?answPV 1))
=>
(open "C:\Users\Jennifer\Desktop\Results.dat" data "r")
(read "C:\Users\Jennifer\Desktop\Results.dat")
(close data)
)
Above we have the following CLIPS code. Everything works up until the file queries. When we run the clips program we receive the following:
[ROUTER1] Logical name C:UsersJenniferDesktopResults.dat was not recognized by any routers
[PRCCODE4] Execution halted during the actions of defrule display_Pap_en_Vleis.
We are trying to display a recipe on the CLIPS command line. Can anybody help?
(defrule display_Pap_en_Vleis
(answerc1 ?answPV)
(test (integerp ?answPV))
(test (= ?answPV 1))
=>
(open "C:\\Users\\Jennifer\\Desktop\\Results.dat" data "r")
(bind ?data (readline data))
(while (neq ?data EOF)
(printout t ?data crlf)
(bind ?data (readline data)))
(close data)
)
Related
I can't find any way to fix having all commands available to all channels. I'm creating a bot
that allows you to play "arcade" games in Discord.
...
client.on('message', (msg) => {
if (message.channel.id != config.singleChannelID) return; // I tried using this, as recommended by other users but I don't know where to put ChannelID.
let prefixd = 'd!'
if (!msg.content.startsWith(prefixd)) return
let command = msg.content.toLowerCase().slice(prefixd.length).split(" ")[0]
if (command == '20') msg.channel.send(`You rolled a(n) **${Math.floor(Math.random() * 20) + 1}**!`)
if (command == '12') msg.channel.send(`You rolled a(n) **${Math.floor(Math.random() * 12) + 1}**!`)
if (command == '8') msg.channel.send(`You rolled a(n) **${Math.floor(Math.random() * 8) + 1}**!`)
if (command == '6') msg.channel.send(`You rolled a(n) **${Math.floor(Math.random() * 6) + 1}**!`)
});
What you have in there will work, but you need to either store the desired channel ID somewhere (config in your example) or just hard code it if that is acceptable for your needs:
if (msg.channel.id != SomeChannelsIdGoesHere) return;
If you don't know how to get the channel ID, consult the discord support pages
Also, note that you used the identifier 'message' instead of 'msg' as it appears in your event callback.
I'm having trouble switching to an iterate version of some loop code:
(defun get-bound-?vars-1 (tree)
(loop for item in tree
when (consp item)
if (member (car item) '(exists forall doall))
nconc (delete-if-not #'?varp
(alexandria:flatten (second item)))
else nconc (get-bound-?vars item)))
My corresponding iterate translation:
(defun get-bound-?vars-2 (tree)
(iter (for item in tree)
(when (consp item)
(if (member (car item) '(exists forall doall))
(nconc (delete-if-not #'?varp
(alexandria:flatten (second item))))
(nconc (get-bound-?vars item))))))
As test case:
(defparameter *tree*
'(if (exists (?t transmitter)
(and (connecting ?t ?connector)
(bind (color ?t $hue))))
(if (not (exists ((?t1 ?t2) transmitter)
(and (connecting ?t1 ?connector)
(connecting ?t2 ?connector)
(bind (color ?t1 $hue1))
(bind (color ?t2 $hue2))
(not (eql $hue1 $hue2)))))
(activate-connector! ?connector $hue))))
Then loop OK:
(get-bound-?vars-1 *tree*) => (?T ?T1 ?T2)
But iterate not OK:
(get-bound-?vars-2 *tree*) => NIL
Thanks for any pointers.
I have been trying to get org-mobile to work on my machine with little
success. I have read many previous answers from this mailing list to no
avail.
When I try to run org-mobile-push I get an error in the minibuffer: "Wrong
type argument: listp, todo".
I have attached a Backtrace of the error and my org-mode settings. I also
attached a debugger eval of the "todo" variable, which I think (I'm not
great at elisp) is causing the error.
Can anyone tell me how I can get org-mobile-push to work correctly?
Cheers!
---- Backtrace and org settings follow ----
Debugger entered--Lisp error: (void-variable todo)
eval(todo)
eval-expression(todo)
debugger-eval-expression(todo)
call-interactively(debugger-eval-expression nil nil)
recursive-edit()
byte-code("\306^P
#\307=\203!^#\310\311\312\"\210\313\311!\211^ZA#)\242\314=\203!^#\310\315\312\"\210\316^K!\210\317
\210\320
!\210\f\203d^#\321ed\"^MV\203W^#eb\210\322^M\245y\210`^^^[db\210\322^M\245^MZy\210^N^[`|\210)\323c\210eb\210\324\325\326
\"\210\327\306!\210\324\330!\210\331\312^^^\^^^]\324\330!\210\212\332
\210+\331\207" [unread-command-char debugger-args x debugger-buffer
noninteractive debugger-batch-max-lines -1 debug backtrace-debug 4 t
backtrace-frame lambda 5 pop-to-buffer debugger-mode debugger-setup-buffer
count-lines 2 "...\n" message "%s" buffer-string kill-emacs "" nil
recursive-edit middlestart buffer-read-only standard-output] 4)
Debugger entered--Lisp error: (wrong-type-argument listp todo)
car(todo)
(setq type (car e) match (nth 1 e) settings (nth 2 e))
(while (setq e (pop cmds)) (setq type (car e) match (nth 1 e) settings
(nth 2 e)) (setq settings (append gsettings settings)) (setq settings (cons
... settings)) (push (list type match settings) new))
(cond ((stringp ...)) ((eq ... ...)) ((memq ... ...)) ((and ... ...))
((memq ... ...) (setq key ... desc ... type ... match ... settings ...)
(setq settings ...) (push ... new)) ((or ... ...)) (t (setq gkey ... gdesc
... gsettings ... cmds ...) (setq cnt 0) (while ... ... ... ... ...)))
(while (setq e (pop thelist)) (cond (...) (...) (...) (...) (... ... ...
...) (...) (t ... ... ...)))
(let ((custom-list ...) (default-list ...) thelist new e key desc type
match settings cmds gkey gdesc gsettings cnt) (cond (... ...) (... ...)
(... ... ... ...) (... ... ...)) (while (setq e ...) (cond ... ... ... ...
... ... ...)) (and new (list "X" "SUMO" ... ...)))
org-mobile-sumo-agenda-command()
(let* ((file ...) (file1 ...) (sumo ...) (org-agenda-custom-commands ...)
(org-mobile-creating-agendas t)) (unless (file-writable-p file1) (error
"Cannot write to file %s" file1)) (when sumo (org-store-agenda-views))
(when org-mobile-use-encryption (org-mobile-encrypt-and-move file1 file)
(delete-file file1) (org-mobile-cleanup-encryption-tempfile)))
org-mobile-create-sumo-agenda()
(let ((inhibit-redisplay t)) (org-mobile-create-sumo-agenda))
(save-window-excursion (run-hooks (quote org-mobile-pre-push-hook))
(org-mobile-check-setup) (org-mobile-prepare-file-lists) (message "Creating
agendas...") (let (...) (org-mobile-create-sumo-agenda)) (message "Creating
agendas...done") (org-save-all-org-buffers) (message "Copying files...")
(org-mobile-copy-agenda-files) (message "Writing index file...")
(org-mobile-create-index-file) (message "Writing checksums...")
(org-mobile-write-checksums) (run-hooks (quote org-mobile-post-push-hook)))
(save-excursion (save-window-excursion (run-hooks ...)
(org-mobile-check-setup) (org-mobile-prepare-file-lists) (message "Creating
agendas...") (let ... ...) (message "Creating agendas...done")
(org-save-all-org-buffers) (message "Copying files...")
(org-mobile-copy-agenda-files) (message "Writing index file...")
(org-mobile-create-index-file) (message "Writing checksums...")
(org-mobile-write-checksums) (run-hooks ...)))
(let ((org-agenda-buffer-name "*SUMO*") (org-agenda-filter
org-agenda-filter) (org-agenda-redo-command org-agenda-redo-command))
(save-excursion (save-window-excursion ... ... ... ... ... ... ... ... ...
... ... ... ... ...)))
(let ((a-buffer ...)) (let (... ... ...) (save-excursion ...))
(redraw-display) (when (and a-buffer ...) (if ... ... ...)))
org-mobile-push()
call-interactively(org-mobile-push t nil)
execute-extended-command(nil)
call-interactively(execute-extended-command nil nil)
Emacs : GNU Emacs 23.2.1 (i686-pc-linux-gnu, GTK+ Version 2.24.4)
of 2011-04-04 on rothera, modified by Debian
Package: Org-mode version 7.7
current state:
(setq
org-log-done 'time
org-export-latex-after-initial-vars-hook '(org-beamer-after-initial-vars)
org-speed-command-hook '(org-speed-command-default-hook
org-babel-speed-command-hook)
org-agenda-custom-commands '(("c" "TODO list, Priority down" todo
"NEXTACTION"
((org-agenda-sorting-strategy (quote (priority-down)))
)
("/media/sf_Conor/todolistprioritydown.ps"))
("x" "Todo List and Agenda"
(todo (quote (priority-down))
(agenda "" (org-agenda-ndays 1)))
((org-agenda-sorting-strategy (quote (time-up))))
("/media/sf_Conor/todolistprioritydown.ps"))
("w" "other Work" tags-todo "DONE"
((org-agenda-files
(quote
("/media/sf_Conor/Dropbox/Orgmode/2011/todo.org"))
)
(org-agenda-sorting-strategy
(quote (priority-up effort-down)))
)
("/media/sf_Conor/computer.html"))
("p" "Priority List" tags-todo
((org-agenda-sorting-strategy (quote (priority-up)))))
)
org-agenda-files '("/media/sf_Conor/Dropbox/Orgmode/2011/
accountmanagement.org"
"/media/sf_Conor/Dropbox/Orgmode/2011/heritage.org"
"/media/sf_Conor/Dropbox/Orgmode/2011/arbitrage.org"
"/media/sf_Conor/Dropbox/Orgmode/2011/kontagent.org"
"/media/sf_Conor/Dropbox/Orgmode/2011/todo.org")
org-blocker-hook '(org-block-todo-from-children-or-siblings-or-parent)
org-agenda-exporter-settings '((ps-number-of-columns 2) (ps-landscape-mode
t)
(org-agenda-add-entry-text-maxlines 5)
(htmlize-output-type (quote css)))
org-metaup-hook '(org-babel-load-in-session-maybe)
org-after-todo-state-change-hook '(wicked/org-clock-out-if-waiting
wicked/org-clock-in-if-starting
org-clock-out-if-current)
org-agenda-todo-ignore-scheduled t
org-show-entry-below t
org-export-blocks-postblock-hook '(org-exp-res/src-name-cleanup)
org-export-latex-format-toc-function 'org-export-latex-format-toc-default
org-mobile-inbox-for-pull "/media/sf_Conor/Dropbox/Orgmode/2011/
from-mobile.org"
org-tab-first-hook '(org-hide-block-toggle-maybe
org-src-native-tab-command-maybe
org-babel-hide-result-toggle-maybe)
org-src-mode-hook '(org-src-babel-configure-edit-buffer
org-src-mode-configure-edit-buffer)
org-confirm-shell-link-function 'yes-or-no-p
org-export-first-hook '(org-beamer-initialize-open-trackers)
org-clock-persist t
org-agenda-before-write-hook '(org-agenda-add-entry-text)
org-agenda-start-with-follow-mode t
org-directory "/media/sf_Conor/Dropbox/Orgmode/2011/"
org-export-docbook-xslt-proc-command ""
org-babel-pre-tangle-hook '(save-buffer)
org-cycle-hook '(org-cycle-hide-archived-subtrees org-cycle-hide-drawers
org-cycle-show-empty-lines
org-optimize-window-after-visibility-change)
org-export-preprocess-before-normalizing-links-hook
'(org-remove-file-link-modifiers)
org-agenda-dim-blocked-tasks nil
org-mode-hook '((lambda nil (org-set-local (quote yas/trigger-key) [tab])
(define-key yas/keymap [tab] (quote yas/next-field-group))
(define-key org-mode-map "\301"
(quote org-archive-to-archive-sibling))
)
org-clock-load
(lambda nil
(org-add-hook (quote change-major-mode-hook)
(quote org-show-block-all) (quote append) (quote local))
)
(lambda nil
(org-add-hook (quote change-major-mode-hook)
(quote org-babel-show-result-all) (quote append) (quote local))
)
org-babel-result-hide-spec org-babel-hide-all-hashes)
org-refile-targets '(:level . 2)
org-ctrl-c-ctrl-c-hook '(org-babel-hash-at-point
org-babel-execute-safely-maybe)
org-confirm-elisp-link-function 'yes-or-no-p
org-export-interblocks '((lob org-babel-exp-lob-one-liners)
(src org-babel-exp-inline-src-blocks))
org-clock-out-hook '(org-clock-remove-empty-clock-drawer)
org-enforce-todo-dependencies t
org-occur-hook '(org-first-headline-recenter)
org-from-is-user-regexp "\\<Conor Nash\\>"
org-mobile-directory "/media/sf_Conor/Dropbox/MobileOrg/"
org-export-preprocess-before-selecting-backend-code-hook
'(org-beamer-select-beamer-code)
org-export-latex-final-hook '(org-beamer-amend-header org-beamer-fix-toc
org-beamer-auto-fragile-frames
org-beamer-place-default-actions-for-lists)
org-metadown-hook '(org-babel-pop-to-session-maybe)
org-export-blocks '((src org-babel-exp-src-block nil)
(comment org-export-blocks-format-comment t)
(ditaa org-export-blocks-format-ditaa nil)
(dot org-export-blocks-format-dot nil))
)
I believe your problem is with the org-agenda-custom-commands variable. In particular you have the value
("x" "Todo List and Agenda"
(todo (quote (priority-down))
(agenda "" (org-agenda-ndays 1)))
((org-agenda-sorting-strategy (quote (time-up))))
("/media/sf_Conor/todolistprioritydown.ps"))
which is the cause of the problem, at least I get the same error when I set org-agenda-custom-commands as you have and run M-x org-agenda RET x. Changing it's value to
("x" "Todo List and Agenda"
((todo (quote (priority-down)))
(agenda "" ((org-agenda-ndays 1))))
((org-agenda-sorting-strategy (quote (time-up))))
("/media/sf_Conor/todolistprioritydown.ps"))
"fixes" the error, but I don't know if it actually does what you want. Note there are extra parentheses in 2 places: around (todo (quote (priority-down))) and ((org-agenda-ndays 1)).
Don't know about the backtracenot a elisper also but I've setup mine using the following post,
http://nakkaya.com/2010/03/19/org-mode-in-your-pocket-setting-up-mobileorg/
My .emacs:
;; enable orgmode en set files
(require 'org-install)
(setq org-directory "~/Dropbox/GTD/")
(add-to-list 'auto-mode-alist '("\\.org$" . org-mode))
(define-key global-map "\C-cl" 'org-store-link)
(define-key global-map "\C-ca" 'org-agenda)
(setq org-log-done t)
(setq org-agenda-files (list (concat org-directory "nextactions.org")
(concat org-directory "projects.org")
(concat org-directory "birthday.org")))
;; Daily action list
(setq org-agenda-custom-commands
'(
("D" "Daily Action List"
(
(agenda "" ((org-agenda-ndays 1)
(org-agenda-sorting-strategy
(quote ((agenda time-up priority-down tag-up) )))
(org-deadline-warning-days 0)
))))
;; Office list
("H" "Office and Home Lists"
((agenda)
(tags-todo "OFFICE")
(tags-todo "HOME")))
)
)
;; Turn on diary within org-mode
(setq org-agenda-include-diary t)
;; Turn on Capture
(setq org-default-notes-file (concat org-directory "notes.org"))
(define-key global-map "\C-cc" 'org-capture)
;; Capture templates
(setq org-capture-templates
'(
("t" "Todo" entry (file+headline (concat org-directory "nextactions.org") "Inbox") "* TODO %?\n %i\n %a")
("j" "Journal" entry (file+datetree (concat org-directory "journal.org")) "* %?\nEntered on %U\n %i\n %a")
)
)
C-c c presents the capture menu buffer. I press then t and capture the buffer that appears (CAPTURE-notes.org). After C-c C-c the entry is added to notes.org instead of nextactions.org section "Inbox".
I have no .emacs parsing errors, how can I fix this so the todo capture-template puts its entry in nextactions.org?
Edit: Setting org-default-notes-file to nextactions.org lets me operate at least the first org-capture template (because its file is the same anyway). The second one stays writing to the default-notes-file.
What org-mode version are you using? I don't remember the exact version, but quoted capture templates were not eval'ed before that.
So you should try either
Update org-mode
use backquotes
(setq org-capture-templates
`(("t" "Todo" entry (file+headline ,(concat org-directory "nextactions.org")
"Inbox")
"* TODO %?\n %i\n %a")
("j" "Journal" entry (file+datetree ,(concat org-directory "journal.org"))
"* %?\nEntered on %U\n %i\n %a")
))
use the literal filepath
(setq org-capture-templates
'(("t" "Todo" entry (file+headline "~/Dropbox/GTD/nextactions.org"
"Inbox")
"* TODO %?\n %i\n %a")
("j" "Journal" entry (file+datetree "~/Dropbox/GTD/journal.org")
"* %?\nEntered on %U\n %i\n %a")
))
Apart from that I see no problem with your config, I use a similar one.
infact you can even refile from the capture buffer to which ever agenda file you want to with C-c C-w.
How to insert a blob in database using the clojure.contrib.sql?
I've tried the following reading from a file but I'm getting this exception:
SQLException:
Message: Invalid column type
SQLState: 99999
Error Code: 17004
java.lang.Exception: transaction rolled back: Invalid column type (repl-1:125)
(clojure.contrib.sql/with-connection
db
(clojure.contrib.sql/transaction
(clojure.contrib.sql/insert-values :test_blob [:blob_id :a_blob] [3 (FileInputStream. "c:/somefile.xls")]) ))
Thanks.
I was able to solve this by converting the FileInputStream into a ByteArray.
(clojure.contrib.sql/with-connection
db
(clojure.contrib.sql/transaction
(clojure.contrib.sql/insert-values :test_blob [:blob_id :a_blob] [3 (to-byte-array(FileInputStream. "c:/somefile.xls"))]) ))
In theory, you can use any of the clojure.contrib.sql/insert-* methods to insert a blob, passing the blob as either a byte array, java.sql.Blob or a java.io.InputStream object. In practice, it is driver-dependent.
For many JDBC implementations, all of the above work as expected, but if you're using sqlitejdbc 0.5.6 from Clojars, you'll find your blob coerced to a string via toString(). All the clojure.contrib.sql/insert-* commands are issued via clojure.contrib.sql/do-prepared, which calls setObject() on a java.sql.PreparedStatement. The sqlitejdbc implementation does not handle setObject() for any of the blob data types, but defaults to coercing them to a string. Here's a work-around that enables you to store blobs in SQLite:
(use '[clojure.contrib.io :only (input-stream to-byte-array)])
(require '[clojure.contrib.sql :as sql])
(defn my-do-prepared
"Executes an (optionally parameterized) SQL prepared statement on the
open database connection. Each param-group is a seq of values for all of
the parameters. This is a modified version of clojure.contrib.sql/do-prepared
with special handling of byte arrays."
[sql & param-groups]
(with-open [stmt (.prepareStatement (sql/connection) sql)]
(doseq [param-group param-groups]
(doseq [[index value] (map vector (iterate inc 1) param-group)]
(if (= (class value) (class (to-byte-array "")))
(.setBytes stmt index value)
(.setObject stmt index value)))
(.addBatch stmt))
(sql/transaction
(seq (.executeBatch stmt)))))
(defn my-load-blob [filename]
(let [blob (to-byte-array (input-stream filename))]
(sql/with-connection db
(my-do-prepared "insert into mytable (blob_column) values (?)" [blob]))))
A more recent reply to this thread with the code to read the data as well :
(ns com.my-items.polypheme.db.demo
(:require
[clojure.java.io :as io]
[clojure.java.jdbc :as sql]))
(def db {:dbtype "postgresql"
:dbname "my_db_name"
:host "my_server"
:user "user",
:password "user"})
(defn file->bytes [file]
(with-open [xin (io/input-stream file)
xout (java.io.ByteArrayOutputStream.)]
(io/copy xin xout)
(.toByteArray xout)))
(defn insert-image [db-config file]
(let [bytes (file->bytes file)]
(sql/with-db-transaction [conn db-config]
(sql/insert! conn :image {:name (.getName file) :data bytes}))))
(insert-image db (io/file "resources" "my_nice_picture.JPG"))
;;read data
(defn read-image [db-config id]
(-> (sql/get-by-id db-config :image id)
:data
(#(new java.io.ByteArrayInputStream %))))
I believe it's just the same way you'd insert any other value: use one of insert-records, insert-rows or insert-values. E.g.:
(insert-values :mytable [:id :blobcolumn] [42 blob])
More examples: http://github.com/richhickey/clojure-contrib/blob/master/src/test/clojure/clojure/contrib/test_sql.clj