How do I turn off quick-and-dirty-subsumption-replacement-step - acl2

When I interrupt my proof, which has gone out to lunch, I see quick-and-dirty-subsumption-replacement-step in the backtrace. How do I disable that heuristic?

Try your proof again after admitting the following two forms:
(defun quick-and-dirty-srs-off (cl1 ac)
(declare (ignore cl1 ac)
(xargs :mode :logic :guard t))
nil)
(defattach quick-and-dirty-srs quick-and-dirty-srs-off)

Related

st-json:write-json - avoid exponent markers for floats

(st-json:write-json-to-string
(st-json:read-json "{\"a\":0.1}"))
Output is not valid JSON:
"{\"a\":1.e-1}"
Desired output:
"{\"a\":0.1}"
I don't see any options or other arguments for write-json-to-string at https://marijnhaverbeke.nl/st-json/
I would still be ok if the number came out a little modified like .1 or 0.10
Update: There is a system variable for float format: "The printer uses *read-default-float-format* to guide the choice of exponent markers when printing floating-point numbers."
According to this example ...
(let ((*read-default-float-format* 'double-float))
(read-from-string "(1.0 1.0e0 1.0s0 1.0f0 1.0d0 1.0L0)"))
==> (1.0d0 1.0d0 1.0 1.0 1.0d0 1.0d0)
The implementation I'm using (SBCL 2.0.11) has float formats F and D. http://www.lispworks.com/documentation/lw50/CLHS/Body/v_rd_def.htm
I'm not sure how "The printer uses *read-default-float-format* to guide the choice of exponent markers when printing floating-point numbers." ... Is there something wrong with my test below?
(progn
(setf *read-default-float-format* 'long-float)
(princ(st-json:write-json-to-string (st-json:read-json "{\"a\":0.1}")))
(setf *read-default-float-format* 'single-float)
(princ(st-json:write-json-to-string (st-json:read-json "{\"a\":0.1}")))
(setf *read-default-float-format* 'double-float)
(princ(st-json:write-json-to-string (st-json:read-json "{\"a\":0.1}")))
(setf *read-default-float-format* 'short-float)
(princ(st-json:write-json-to-string (st-json:read-json "{\"a\":0.1}"))))
{"a":1.e-1}{"a":1.e-1}{"a":1.e-1}{"a":1.e-1}
==> "{\"a\":1.e-1}"
Thanks in advance for any help!
It got nothing to do with *read-default-float-format*.
Using M-. in SLIME, I could see that write-json-to-string calls write-json which in turn calls write-json-element.
write-json-element is a generic function with different methods for different type. method for real is:
(defmethod write-json-element ((element real) stream)
(format stream "~,,,,,,'eE" element))
That format string is standard Common Lisp, resulting in the behaviour you are seeing.
CL-USER> (format t "~,,,,,,'eE" 0.1)
1.e-1
NIL
CL-USER>
I have no idea why author did that, but if you are stuck with st-json, Just redefine the method as (which will issue a re-definition warning, but ignore that):
(defmethod st-json:write-json-element ((element real) stream)
(format stream "~F" element))
However, if you could switch to another library, take a look at jzon, it is in latest Quicklisp.

Dynamically bound variable : revert to previous state

I'm trying to understand dynamical and lexical bindings of a variable.
I was browsing SO and some links, when I encountered a problem on this one :
https://www.emacswiki.org/emacs/DynamicBindingVsLexicalBinding#toc2
I ran this code :
(let ((a 1))
(let ((f (lambda () (print a))))
(let ((a 2))
(funcall f))))
With expected result : 1 (and a warning which says that the second a variable is unused, which is normal).
Next, I tried :
(defvar a 99)
And reran the first code. Result is 2, like the tutorial says. Then, to experiment further, I tried to remove the dynamically binding variable a, to get again 1.
I tried to (makunbound 'a) or even (setq a 55) (I tried this by default, I think global lexical binding depends on implementation if I understand correctly...). makunbound seems to remove the symbol, but the "dynamically binding state" seems to be saved anyway. The result is still 2.
How can I reset Common Lisp to the previous state (before I dynamically bind the a variable) ? Restart SLIME do the trick, but I would rather have a way to do it programatically...
Thank you for your answer.
There is no portable way to revert the
special
proclaimation.
(CLISP offers
notspecial).
However, you can use unintern
to some extent: it will make new code treat your symbol as not
special because it is now a different symbol:
(defun test-a ()
(let ((a 1))
(let ((f (lambda () (print a))))
(let ((a 2))
(funcall f)))))
(test-a)
==> 1
(defvar a)
(test-a)
==> 2
now, let us try to "revert" defvar:
(unintern 'a)
(test-a)
==> 2
oops! Let us see:
(fdefinition 'test-a)
#<FUNCTION TEST-A NIL (DECLARE (SYSTEM::IN-DEFUN TEST-A))
(BLOCK TEST-A
(LET ((#:A 1)) (LET ((F (LAMBDA NIL (PRINT #:A)))) (LET ((#:A 2)) (FUNCALL F)))))>
you see, test-a is still using the old symbol a which is now uninterned (so printed as #:A). To get back, you need to re-eval the defun above and then you get
(test-a)
==> 1
again!

Disable too-many-ifs heuristic

How do I disable the too-many-ifs heuristic? Sometimes the prover goes out to lunch, and when I interrupt it, I can see that the prover is busy with a call of too-many-ifs0 and count-ifs-lst.
You can convert the too-many-ifs heuristic into an effective no-op by issuing the following forms. Note that if you're using these in a book, you probably want to make each of the below forms "local":
(defn too-many-ifs-pre-rewrite-noop (args counts)
(declare (ignore args counts))
nil)
(defattach too-many-ifs-pre-rewrite too-many-ifs-pre-rewrite-noop)
(defn too-many-ifs-post-rewrite-noop (args counts)
(declare (ignore args counts))
nil)
(defattach too-many-ifs-post-rewrite too-many-ifs-post-rewrite-noop)

Emacs automating function based on timer: user disturbance

I am looking for a general way for Emacs to do some checks, and (bing) when something is true or false.
I have 2 examples at the moment. There is an auction website, and I figured it would be nice for Emacs to check whether there has been an update. I did this using R (Emacs-ESS) to load source code of the website. Then I use a selfmade function in Emacs to:
Switch buffer, reload the URL info, send the info to the screen, (sleep-for ) to wait a little. Search for "Today". Then it has to check the value after this string, if it is higher than 0, then it means I have something new of interest, and it PINGS.
This is a long introduction, but I really like that this works.
I now do the same with Gnus, I have a timer that runs a function that opens Gnus every 10 seconds, searches for "Inbox", checks the value, and if it is higher than 0 then it notifies me (otherwise it just switches the buffer back). The only problem is that this takes around 0.5 seconds, in which you can see point move to another buffer and switch back.
Is there a general approach to have these automated things be done, without disturbing the user?
EDIT: Wouldn't it be nice for Emacs to perform a check to see whether there is a new post with our favorite tag here on Stackoverflow?
Emacs is single-threaded, so we are screwed - there is not way to do this without bothering the user at all.
The trick is to select a good balance between the frequency and cost of the check so that the user can bear it.
Here is the code I used once:
(defvar sds-new-mail-line nil "cache")
(defun sds-new-mail-line (&optional arg)
"add or remove the mode-line new-mail marker"
(or sds-new-mail-line (error "sds-new-mail-line has not been initialized"))
(let* ((mlf (default-value 'mode-line-format))
(already-have (eq sds-new-mail-line (car mlf))))
(if (or (eq arg nil) (< arg 0))
(when already-have
(setq-default mode-line-format (cdr mlf)))
(unless already-have
(setq-default mode-line-format (cons sds-new-mail-line mlf))))))
(defun sds-gnus-scan-mail ()
"check for new mail, notify if there is some"
(when (gnus-alive-p)
(with-current-buffer gnus-group-buffer
(gnus-group-get-new-news 3)
(gnus-group-get-new-news 2)
(goto-char (point-min))
;; look for new messages in groups of level 1 and 2
(cond ((search-forward-regexp "^ *s[12] *[1-9][0-9]*n" nil t)
(message "you have new mail! (%s)" (user-time-format))
(sds-new-mail-line 1)
(ding))
(t (sds-new-mail-line -1)
(message "no new mail (%s)" (user-time-format))))
(goto-char (point-min)))))
(defun sds-gnus-load-hook ()
(unless sds-new-mail-line ; init
(let ((str "mail") (map (make-sparse-keymap)))
(define-key map [mode-line down-mouse-1] 'ignore)
(define-key map [mode-line mouse-1] read-mail-command)
(add-text-properties 0 (length str)
(list 'display gnus-mode-line-image-cache
'help-echo "you have new mail - read it!"
'local-map map)
str)
(setq sds-new-mail-line str))
(gnus-demon-add-handler 'sds-gnus-scan-mail 3 t))
(add-hook 'gnus-summary-prepared-hook 'gnus-summary-first-unread-subject)
(add-hook 'gnus-summary-prepare-exit-hook 'gnus-summary-catchup))
;; cannot use gnus-load-hook here!
(eval-after-load "gnus-start" '(sds-gnus-load-hook))
I am sure you can adapt it to your needs.

"Unable to resolve symbol" error

When I paste this code into a REPL, it works fine:
(use 'clojure.contrib.seq-utils)
(defn- random-letter [] (char (+ (rand-int 26) 97)))
(defn- random-digit [] (rand-int 10))
(defn- random-password
"Returns an 8-character password consisting of letters and digits as follows: aa1aa1aa"
[]
(let [password (interpose '((random-digit)) (repeat 3 (repeat 2 '(random-letter))))]
(apply str (flatten (map (fn [coll] (map eval coll)) password)))))
Now, I have this code with :gen-class :implements [my.ServiceInterface] and a function prefixed with - to implement the interface. I unit-test with Maven/Groovy/TestNG. Everything works fine with several other interfaces/Clojure implementations, but in this particular case, I get this error:
java.lang.RuntimeException:
java.lang.Exception: Unable to resolve symbol: random-letter in this context (NO_SOURCE_FILE:32)
I can't figure out why. The only thing I can tell is different in this function from all the other functions, is that this is the only place where I use quoting, i.e. '((random-digit)) and '(random-letter). EDIT: also, this is the only place where I use eval.
I tried defining the functions as "non-private" (defn instead of defn-). I also tried a (declare random-digit random-letter) at the top. Neither of these solves the problem.
On a side note, if you have a suggestion for a better way to implement the random-password function, I am all ears. But I'd still like to know why I am getting this error and how to get this to work.
Many thanks in advance for your help. Clojure is awesome.
Edit: here is the complete code.
(ns fred.hp2010.service.ClojurePoolerService
(:gen-class :implements [fred.hp2010.service.PoolerService])
(:use [clojure.contrib.seq-utils :only (flatten)]))
(def dao (fred.hp2010.persistence.Repository/getDao))
(declare find-by is-taken random-password)
(defn -addPooler [this pooler] (. dao insert "POOLER" pooler))
(defn -getPoolers [this] (. dao list "poolers"))
(defn -isEmailTaken [this email] (is-taken {"email" email}))
(defn -isUsernameTaken [this username] (is-taken {"username" username}))
(defn -login [this email password] (. dao findSingle "POOLER" {"email" email "password" password}))
(defn -changePassword [this email new-password]
(let [updated-pooler (assoc (into {} (find-by {"email" email})) "password" new-password)]
(. dao update "POOLER" "POOLER_ID" updated-pooler)))
(defn -resetPassword [this email]
(let [new-password (random-password)]
(-changePassword this email new-password)
new-password))
(defn- find-by [params] (. dao findSingle "POOLER" params))
(defn- is-taken [params] (not (nil? (find-by params))))
(defn- random-letter [] (char (+ (rand-int 26) 97)))
(defn- random-digit [] (rand-int 10))
(defn- random-password
"Returns an 8-character password consisting of letters and digits as follows: aa1aa1aa"
[]
(let [password (interpose '((random-digit)) (repeat 3 (repeat 2 '(random-letter))))]
(apply str (flatten (map (fn [coll] (map eval coll)) password)))))
I don't know why you're having problems compiling this with :gen-class but I wouldn't be surprised if eval had something to do with it. eval is usually a bad idea. One thing to try (completely untested) is to use ` (backquote) instead of ' (quote) so that your symbols are namespace-qualified. Don't know if that'd help or not.
Probably better to get rid of eval though. If you turn your random-character functions into infinite lazy seqs via repeatedly you can do it this way:
(defn- random-letter [] (repeatedly #(char (+ (rand-int 26) 97))))
(defn- random-digit [] (repeatedly #(rand-int 10)))
(defn- random-password
"Returns an 8-character password consisting of letters and digits as follows: aa1aa1aa"
[]
(apply str
(mapcat (fn [[n f]] (take n (f)))
[[2 random-letter]
[1 random-digit]
[2 random-letter]
[1 random-digit]
[2 random-letter]])))
In the top handful of lines, I'm having a bit of trouble following the syntax. In particular, why all the quotes in line 7? Delayed evaluation of all those expressions is probably not helping you. I would guess that the quoted '(random-letter) is spoiling your fun.
You can probably write simpler code while eschewing eval. I'm going to go try it in the REPL, I hope to be back soon with an improved version.
EDIT:
OK, this works:
(apply str (interpose (random-digit) (repeat 3 (apply str (repeat 2 (random-letter))))))
...and it doesn't need anything from clojure.contrib :)
The str function will mung any arguments together into a string. If the arguments are in a list, you smuggle str inside the list by using apply.
As you said, Clojure is cool!
EDIT:
Here's a function that generates a random string of alphas and numerics in accordance with a String specification:
(apply str (map (fn [c] (if (= c \a) (random-letter) (random-digit))) "aanaanaa")))
It deviates a little bit from your spec but I think it's pretty cool.

Resources