Running simple HTTP-request:
with dexador or drakma
and on SBCL 1.4.14
and on OS X 10.13.6
with (ql:client-version) equals to "2017-03-06" and (defvar qlqs-info:*version* "2015-01-28" (I've just installed Quicklisp from https://www.quicklisp.org/beta/ via https://beta.quicklisp.org/quicklisp.lisp)
via Emacs+SLIME or just from the command line using only SBCL
(dex:get "http://localhost:8000/wp-json/wp/v2/posts")
fails with the error (dex stacktrace)
Condition USOCKET:CONNECTION-REFUSED-ERROR was signalled.
[Condition of type USOCKET:CONNECTION-REFUSED-ERROR]
Backtrace:
0: (USOCKET::HANDLE-CONDITION #<SB-BSD-SOCKETS:CONNECTION-REFUSED-ERROR {1008622AF3}> #<USOCKET:STREAM-USOCKET {1008622583}>)
1: (SB-KERNEL::%SIGNAL #<SB-BSD-SOCKETS:CONNECTION-REFUSED-ERROR {1008622AF3}>)
2: (ERROR SB-BSD-SOCKETS:CONNECTION-REFUSED-ERROR :ERRNO 61 :SYSCALL "connect")
3: (SB-BSD-SOCKETS:SOCKET-ERROR "connect" 61)
4: (SB-BSD-SOCKETS::CALL-WITH-SOCKET-ADDR #<SB-BSD-SOCKETS:INET-SOCKET 127.0.0.1:59367, fd: 17 {1008622473}> (#(127 0 0 1) 8000) #<CLOSURE (FLET SB-BSD-SOCKETS::WITH-SOCKET-ADDR-THUNK :IN SB-BSD-SOCKETS:..
5: ((:METHOD SB-BSD-SOCKETS:SOCKET-CONNECT (SB-BSD-SOCKETS:SOCKET)) #<SB-BSD-SOCKETS:INET-SOCKET 127.0.0.1:59367, fd: 17 {1008622473}> #(127 0 0 1) 8000) [fast-method]
6: ((FLET "WITHOUT-INTERRUPTS-BODY-22" :IN USOCKET:SOCKET-CONNECT))
7: (USOCKET:SOCKET-CONNECT "localhost" 8000 :PROTOCOL :STREAM :ELEMENT-TYPE (UNSIGNED-BYTE 8) :TIMEOUT 10 :DEADLINE NIL :NODELAY T :LOCAL-HOST NIL :LOCAL-PORT NIL)
8: ((LABELS DEXADOR.BACKEND.USOCKET::MAKE-NEW-CONNECTION :IN DEXADOR.BACKEND.USOCKET:REQUEST) #<QURI.URI.HTTP:URI-HTTP http://localhost:8000/wp-json/wp/v2/posts
9: (DEXADOR.BACKEND.USOCKET:REQUEST #<unavailable argument> :METHOD :GET)
10: (SB-INT:SIMPLE-EVAL-IN-LEXENV (DEXADOR:GET "http://localhost:8000/wp-json/wp/v2/posts") #<NULL-LEXEN..
11: (EVAL (DEXADOR:GET "http://localhost:8000/wp-json/wp/v2/posts"))
or (drakma stacktrace)
Condition USOCKET:CONNECTION-REFUSED-ERROR was signalled.
[Condition of type USOCKET:CONNECTION-REFUSED-ERROR]
Restarts:
0: [RETRY] Retry SLIME REPL evaluation request.
1: [*ABORT] Return to SLIME's top level.
2: [ABORT] abort thread (#<THREAD "repl-thread" RUNNING {1003CE8413}>)
Backtrace:
0: (USOCKET::HANDLE-CONDITION #<SB-BSD-SOCKETS:CONNECTION-REFUSED-ERROR {1005657693}> #<USOCKET:STREAM-USOCKET {1005657123}>)
1: (SB-KERNEL::%SIGNAL #<SB-BSD-SOCKETS:CONNECTION-REFUSED-ERROR {1005657693}>)
2: (ERROR SB-BSD-SOCKETS:CONNECTION-REFUSED-ERROR :ERRNO 61 :SYSCALL "connect")
3: (SB-BSD-SOCKETS:SOCKET-ERROR "connect" 61)
4: (SB-BSD-SOCKETS::CALL-WITH-SOCKET-ADDR #<SB-BSD-SOCKETS:INET-SOCKET 127.0.0.1:59799, fd: 12 {1005657013}> (#(127 0 0 1) 8000) #<CLOSURE (FLET SB-BSD-SOCKETS::WITH-SOCKET-ADDR-THUNK :IN SB-BSD-SOCKETS:..
5: ((:METHOD SB-BSD-SOCKETS:SOCKET-CONNECT (SB-BSD-SOCKETS:SOCKET)) #<SB-BSD-SOCKETS:INET-SOCKET 127.0.0.1:59799, fd: 12 {1005657013}> #(127 0 0 1) 8000) [fast-method]
6: ((FLET "WITHOUT-INTERRUPTS-BODY-22" :IN USOCKET:SOCKET-CONNECT))
7: (USOCKET:SOCKET-CONNECT "localhost" 8000 :PROTOCOL :STREAM :ELEMENT-TYPE FLEXI-STREAMS:OCTET :TIMEOUT 20 :DEADLINE NIL :NODELAY :IF-SUPPORTED :LOCAL-HOST NIL :LOCAL-PORT NIL)
8: (DRAKMA:HTTP-REQUEST #<PURI:URI http://localhost:8000/wp-json/wp/v2/posts>)
9: (SB-INT:SIMPLE-EVAL-IN-LEXENV (DRAKMA:HTTP-REQUEST "http://localhost:8000/wp-json/wp/v2/posts") #<NULL-LEXENV>)
10: (EVAL (DRAKMA:HTTP-REQUEST "http://localhost:8000/wp-json/wp/v2/posts"))
11: (SWANK::EVAL-REGION "(drakma:http-request \"http://localhost:8000/wp-json/wp/v2/posts\") ..)
12: ((LAMBDA NIL :IN SWANK-REPL::REPL-EVAL))
13: (SWANK-REPL::TRACK-PACKAGE #<CLOSURE (LAMBDA NIL :IN SWANK-REPL::REPL-EVAL) {10056566CB}>)
14: (SWANK::CALL-WITH-RETRY-RESTART "Retry SLIME REPL evaluation request." #<CLOSURE (LAMBDA NIL :IN SWANK-REPL::REPL-EVAL) {100565666B}>)
15: (SWANK::CALL-WITH-BUFFER-SYNTAX NIL #<CLOSURE (LAMBDA NIL :IN SWANK-REPL::REPL-EVAL) {100565664B}>)
16: (SWANK-REPL::REPL-EVAL "(drakma:http-request \"http://localhost:8000/wp-json/wp/v2/posts\") ..)
17: (SB-INT:SIMPLE-EVAL-IN-LEXENV (SWANK-REPL:LISTENER-EVAL "(drakma:http-request \"http://localhost:8000/wp-json/wp/v2/posts\") ..)
18: (EVAL (SWANK-REPL:LISTENER-EVAL "(drakma:http-request \"http://localhost:8000/wp-json/wp/v2/posts\") ..)
19: (SWANK:EVAL-FOR-EMACS (SWANK-REPL:LISTENER-EVAL "(drakma:http-request \"http://localhost:8000/wp-json/wp/v2/posts\") ..)
20: (SWANK::PROCESS-REQUESTS NIL)
21: ((LAMBDA NIL :IN SWANK::HANDLE-REQUESTS))
22: ((LAMBDA NIL :IN SWANK::HANDLE-REQUESTS))
23: (SWANK/SBCL::CALL-WITH-BREAK-HOOK #<FUNCTION SWANK:SWANK-DEBUGGER-HOOK> #<CLOSURE (LAMBDA NIL :IN SWANK::HANDLE-REQUESTS) {1003CF008B}>)
24: ((FLET SWANK/BACKEND:CALL-WITH-DEBUGGER-HOOK :IN "/Users/ihar/quicklisp/dists/quicklisp/software/slime-v2.22/swank/sbcl.lisp") #<FUNCTION SWANK:SWANK-DEBUGGER-HOOK> #<CLOSURE (LAMBDA NIL :IN SWANK::HA..
25: (SWANK::CALL-WITH-BINDINGS ((*STANDARD-INPUT* . #1=#<SWANK/GRAY::SLIME-INPUT-STREAM {1003BEA693}>) (*STANDARD-OUTPUT* . #2=#<SWANK/GRAY::SLIME-OUTPUT-STREAM {1003CC8CF3}>) (*TRACE-OUTPUT* . #2#) (*ERR..
26: (SWANK::HANDLE-REQUESTS #<SWANK::MULTITHREADED-CONNECTION {10032427F3}> NIL)
27: ((FLET SB-UNIX::BODY :IN SB-THREAD::INITIAL-THREAD-FUNCTION-TRAMPOLINE))
28: ((FLET "WITHOUT-INTERRUPTS-BODY-4" :IN SB-THREAD::INITIAL-THREAD-FUNCTION-TRAMPOLINE))
29: ((FLET SB-THREAD::WITH-MUTEX-THUNK :IN SB-THREAD::INITIAL-THREAD-FUNCTION-TRAMPOLINE))
30: ((FLET "WITHOUT-INTERRUPTS-BODY-1" :IN SB-THREAD::CALL-WITH-MUTEX))
31: (SB-THREAD::CALL-WITH-MUTEX #<CLOSURE (FLET SB-THREAD::WITH-MUTEX-THUNK :IN SB-THREAD::INITIAL-THREAD-FUNCTION-TRAMPOLINE) {3A67D6B}> #<SB-THREAD:MUTEX "thread result lock" owner: #<SB-THREAD:THREAD "..
32: (SB-THREAD::INITIAL-THREAD-FUNCTION-TRAMPOLINE #<SB-THREAD:THREAD "repl-thread" RUNNING {1003CE8413}> NIL #<CLOSURE (LAMBDA NIL :IN SWANK-REPL::SPAWN-REPL-THREAD) {1003CE83BB}> NIL)
33: ("foreign function: call_into_lisp")
34: ("foreign function: new_thread_trampoline")
35: ("foreign function: _pthread_body")
36: ("foreign function: _pthread_body")
37: ("foreign function: thread_start")
Running the same request on Clozure Common Lisp Version 1.11.5 (DarwinX8664) works good.
Does somebody know the reason?
I had the same situation and I noticed my local services which Drakma tried to reach were ipv6 based, so they listened at ::1, when I set those service to listen at 127.0.0.1:xxxx explicitly instead of localhost:xxxx they became ipv4 and Drakma didn't complain any more.
Related
I just installed the Common Lisp kernel on Jupyter but I cannot run even the simplest function.
For example, when I run:
(+ 2 3)
I get the following error output:
SIMPLE-PROGRAM-ERROR: invalid number of arguments: 7
3: ((FLET "H1" :IN JUPYTER:EVALUATE-CODE) invalid number of arguments: 7)
4: (SB-KERNEL::%SIGNAL invalid number of arguments: 7)
5: (ERROR invalid number of arguments: 7)
6: (SB-INT:%PROGRAM-ERROR invalid number of arguments: ~S 7)
7: ("INVALID-ARG-COUNT-ERROR" 7)
8: (SB-KERNEL:INTERNAL-ERROR #.(SB-SYS:INT-SAP #X0360CB30) #<unused argument>)
9: ("foreign function: call_into_lisp")
10: ("foreign function: funcall2")
11: ("foreign function: interrupt_internal_error")
12: ("foreign function: signal_emulation_wrapper")
13: (SB-C:COMPILE-IN-LEXENV (LAMBDA NIL (PROGN (+ 2 3))) #<NULL-LEXENV> NIL #<SOURCE-INFO {10054FB893}> 0 NIL NIL)
14: (JUPYTER/COMMON-LISP::EVAL-AND-PRINT (+ 2 3) 0 NIL)
15: ((:METHOD JUPYTER:EVALUATE-FORM (JUPYTER/COMMON-LISP:KERNEL T T T)) #<unused argument> #<FORM-TRACKING-STREAM for "file /private/var/folders/2m/jgjftc_50v7174pkpy0q6g4c0000gn/T/8D5CF88911FF45F031383A7D6553D461-2332295794.lisp" {10054FCE53}> CELL:2332295794.LISP.NEWEST NIL #<unused argument> #<unused argument>)
16: (JUPYTER/COMMON-LISP::REPL (+ 2 3) CELL:2332295794.LISP.NEWEST NIL)
17: ((:METHOD JUPYTER:EVALUATE-CODE (JUPYTER/COMMON-LISP:KERNEL T)) #<unused argument> (+ 2 3) CELL:2332295794.LISP.NEWEST NIL)
18: (JUPYTER::HANDLE-EXECUTE-REQUEST)
19: (JUPYTER::RUN-SHELL #<KERNEL {10034490D3}>)
20: ((LAMBDA NIL :IN BORDEAUX-THREADS::BINDING-DEFAULT-SPECIALS))
21: ((FLET SB-UNIX::BODY :IN SB-THREAD::INITIAL-THREAD-FUNCTION-TRAMPOLINE))
22: ((FLET "WITHOUT-INTERRUPTS-BODY-4" :IN SB-THREAD::INITIAL-THREAD-FUNCTION-TRAMPOLINE))
23: ((FLET SB-THREAD::WITH-MUTEX-THUNK :IN SB-THREAD::INITIAL-THREAD-FUNCTION-TRAMPOLINE))
24: ((FLET "WITHOUT-INTERRUPTS-BODY-1" :IN SB-THREAD::CALL-WITH-MUTEX))
25: (SB-THREAD::CALL-WITH-MUTEX #<CLOSURE (FLET SB-THREAD::WITH-MUTEX-THUNK :IN SB-THREAD::INITIAL-THREAD-FUNCTION-TRAMPOLINE) {360DD3B}> #<MUTEX "thread result lock" owner: #<SB-THREAD:THREAD "SHELL Thread" RUNNING {1004762CB3}>> NIL T NIL)
26: (SB-THREAD::INITIAL-THREAD-FUNCTION-TRAMPOLINE #<THREAD "SHELL Thread" RUNNING {1004762CB3}> NIL #<CLOSURE (LAMBDA NIL :IN BORDEAUX-THREADS::BINDING-DEFAULT-SPECIALS) {1004762C5B}> NIL)
27: ("foreign function: call_into_lisp")
28: ("foreign function: new_thread_trampoline")
29: ("foreign function: _pthread_body")
30: ("foreign function: _pthread_body")
31: ("foreign function: thread_start")
Not sure why it says I have 7 arguments when there are only two.
I followed all the instructions and even installed the zeromq and czmq packages with homebrew.
Any thoughts? Did I miss anything during the installation process?
Here's a screenshot:
Error in Jupyter Labs with Common Lisp code
I'm puzzled with results of computing sequence by different ways:
(defun fig-square-p (n)
"Check if the given N is a perfect square number.
A000290 in the OEIS"
(check-type n (integer 0 *))
(= (floor (sqrt n)) (ceiling (sqrt n))))
(defun fibonaccip (n)
"Check if the given number N is a Fibonacci number."
(check-type n (integer 0 *))
(or (fig-square-p (+ (* 5 (expt n 2)) 4))
(fig-square-p (- (* 5 (expt n 2)) 4))))
(defun fibonacci (n)
"Compute N's Fibonacci number."
(check-type n (integer 0 *))
(loop :for f1 = 0 :then f2
:and f2 = 1 :then (+ f1 f2)
:repeat n :finally (return f1)))
(defun seq-fibonaccies (n)
"Return sequence of Fibonacci numbers upto N."
(check-type n (integer 0 *))
(loop :for i :from 1 :upto n
:collect (fib i)))
CL-USER> (loop :for i :from 0 :upto 7070 :when (fibonaccip i) :collect i)
(0 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 2889 3876 4181 5473
6765 7070)
CL-USER> (seq-fibonaccies 21)
(1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 10946)
And when I increasing the limit of the loop the results start diverging much more.
~$ sbcl --version
SBCL 1.4.14-3.fc31
As someone else already mentioned, rounding errors accumulate quickly,
so you should stick with the integer arithmetics, using
isqrt:
(defun squarep (n)
"Check if the given N is a perfect square number.
https://oeis.org/A000290"
(check-type n (integer 0 *))
(let ((sqrt (isqrt n)))
(= n (* sqrt sqrt))))
Also, you have a typo in seq-fibonaccies (fib instead of fibonacci).
Finally, seq-fibonaccies is quadratic in its argument, while it only
have to be linear.
fibonaccip is going to give an estimated value because you don't have exact values for the square root of 5. As the value of n increases, the error will also incresase.
I want to demean a whole data.table object (or just a list of many columns of it) by groups.
Here's my approach so far:
setkey(myDt, groupid)
for (col in colnames(wagesOfFired)){
myDt[, paste(col, 'demeaned', sep='.') := col - mean(col), with=FALSE]
}
which gives
Error in col - mean(col) : non-numeric argument to binary operator
Here's some sample data. In this simple case, there's only two columns, but I typically have so many columns such that I want to iterate over a list
y groupid x
1: 3.46000 51557094 97
2: 111.60000 51557133 25
3: 29.36000 51557133 23
4: 96.38000 51557133 9
5: 65.22000 51557193 32
6: 66.05891 51557328 10
7: 9.74000 51557328 180
8: 61.59000 51557328 18
9: 9.99000 51557328 18
10: 89.68000 51557420 447
11: 129.24436 51557429 15
12: 3.46000 51557638 3943
13: 117.36000 51557642 11
14: 9.51000 51557653 83
15: 68.16000 51557653 518
16: 96.38000 51557653 14
17: 9.53000 51557678 18
18: 7.96000 51557801 266
19: 51.88000 51557801 49
20: 10.70000 51558040 1034
The problem is that col is a string, so col-mean(col) cannot be computed.
myNames <- names(myDt)
myDt[,paste(myNames,"demeaned",sep="."):=
lapply(.SD,function(x)x-mean(x)),
by=groupid,.SDcols=myNames]
Comments:
You don't need to set a key.
It's in one operation because using [ repeatedly can be slow.
You can change myNames to some subset of the column names.
When I key command "SHOW ENGINE INNODB STATUS\g;" to show the status. I found there is deadlock. It indicates the deadlock occurs in table TaskInfo. But what is "HT_TaskInfo"? I did not create this table. Will anybody kindly explain me what exactly caused the deadlock?
------------------------
LATEST DETECTED DEADLOCK
------------------------
141009 22:55:13
*** (1) TRANSACTION:
TRANSACTION 0 333298183, ACTIVE 1 sec, OS thread id 5628 starting index read
mysql tables in use 1, locked 1
LOCK WAIT 2 lock struct(s), heap size 368, 1 row lock(s)
MySQL thread id 4591, query id 1071477 10.0.0.4 ptrackUser Updating
update TaskInfo set actualHB='2014-10-09 22:56:00', actualHO='2014-10-09 22:55:05', assignee_username='7438', assigner_username='P0041057', basi
Task_id=19429, clientQualityRequirement=null, confirmscore=0.0, createDate='2014-10-08 10:02:45', creater='7438', deliverables=null, dis_id=null
hipmStatus=null, instruction=null, isnewHipmTask=0, isrework=0, jobBatch_id=null, ongoing=0, parentTask=41641, plannedHB='2014-10-09 09:00:00',
plannedHO='2014-10-08 10:03:00', reason=null, reworkTaskId=null, score=null, sourceFilePath=null, status=2, subType=0, taskBatch_id=88410, taskC
de=null, type='1', unit='Words', volume=1661.0 where taskId=41878
*** (1) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 0 page no 689799 n bits 176 index `PRIMARY` of table `ptrack`.`taskinfo` trx id 0 333298183 lock_mode X locks rec but not
ap waiting
Record lock, heap no 108 PHYSICAL RECORD: n_fields 37; compact format; info bits 0
0: len 4; hex 8000a396; asc ;; 1: len 6; hex 000013ddb9f6; asc ;; 2: len 7; hex 00000634cc0938; asc 4 8;; 3: len 4; hex 00a0cf44;
asc D;; 4: SQL NULL; 5: len 8; hex 8000125171b34721; asc Qq G!;; 6: SQL NULL; 7: SQL NULL; 8: SQL NULL; 9: len 8; hex 8000125171b135d0; as
Qq 5 ;; 10: len 8; hex 8000125171a21bcc; asc Qq ;; 11: len 4; hex 80000001; asc ;; 12: len 1; hex 31; asc 1;; 13: len 5; hex 576f72
473; asc Words;; 14: len 4; hex 37343338; asc 7438;; 15: len 4; hex 80004be5; asc K ;; 16: SQL NULL; 17: SQL NULL; 18: SQL NULL; 19: len 4; he
8000a2a9; asc ;; 20: len 8; hex 5030303431303537; asc P0041057;; 21: SQL NULL; 22: len 4; hex 8001595a; asc YZ;; 23: len 1; hex 80; asc
; 24: len 8; hex 8000125171a21b95; asc Qq ;; 25: len 4; hex 37343338; asc 7438;; 26: len 4; hex 80000000; asc ;; 27: SQL NULL; 28: SQL
ULL; 29: SQL NULL; 30: len 1; hex 80; asc ;; 31: SQL NULL; 32: len 1; hex 80; asc ;; 33: SQL NULL; 34: len 4; hex 00000000; asc ;; 35: SQL
NULL; 36: SQL NULL;
*** (2) TRANSACTION:
TRANSACTION 0 333298182, ACTIVE 1 sec, OS thread id 5596 fetching rows, thread declared inside InnoDB 419
mysql tables in use 2, locked 2
423 lock struct(s), heap size 47088, 36018 row lock(s), undo log entries 1
MySQL thread id 4589, query id 1071475 10.0.0.4 ptrackUser Sending data
update TaskInfo set hipmStatus='FAIL' where (taskId) IN (select taskId from HT_TaskInfo)
*** (2) HOLDS THE LOCK(S):
RECORD LOCKS space id 0 page no 689799 n bits 176 index `PRIMARY` of table `ptrack`.`taskinfo` trx id 0 333298182 lock mode S locks rec but not
ap
Record lock, heap no 108 PHYSICAL RECORD: n_fields 37; compact format; info bits 0
0: len 4; hex 8000a396; asc ;; 1: len 6; hex 000013ddb9f6; asc ;; 2: len 7; hex 00000634cc0938; asc 4 8;; 3: len 4; hex 00a0cf44;
asc D;; 4: SQL NULL; 5: len 8; hex 8000125171b34721; asc Qq G!;; 6: SQL NULL; 7: SQL NULL; 8: SQL NULL; 9: len 8; hex 8000125171b135d0; as
Qq 5 ;; 10: len 8; hex 8000125171a21bcc; asc Qq ;; 11: len 4; hex 80000001; asc ;; 12: len 1; hex 31; asc 1;; 13: len 5; hex 576f72
473; asc Words;; 14: len 4; hex 37343338; asc 7438;; 15: len 4; hex 80004be5; asc K ;; 16: SQL NULL; 17: SQL NULL; 18: SQL NULL; 19: len 4; he
8000a2a9; asc ;; 20: len 8; hex 5030303431303537; asc P0041057;; 21: SQL NULL; 22: len 4; hex 8001595a; asc YZ;; 23: len 1; hex 80; asc
; 24: len 8; hex 8000125171a21b95; asc Qq ;; 25: len 4; hex 37343338; asc 7438;; 26: len 4; hex 80000000; asc ;; 27: SQL NULL; 28: SQL
ULL; 29: SQL NULL; 30: len 1; hex 80; asc ;; 31: SQL NULL; 32: len 1; hex 80; asc ;; 33: SQL NULL; 34: len 4; hex 00000000; asc ;; 35: SQL
NULL; 36: SQL NULL;
*** (2) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 0 page no 689799 n bits 176 index `PRIMARY` of table `ptrack`.`taskinfo` trx id 0 333298182 lock_mode X waiting
Record lock, heap no 108 PHYSICAL RECORD: n_fields 37; compact format; info bits 0
0: len 4; hex 8000a396; asc ;; 1: len 6; hex 000013ddb9f6; asc ;; 2: len 7; hex 00000634cc0938; asc 4 8;; 3: len 4; hex 00a0cf44;
asc D;; 4: SQL NULL; 5: len 8; hex 8000125171b34721; asc Qq G!;; 6: SQL NULL; 7: SQL NULL; 8: SQL NULL; 9: len 8; hex 8000125171b135d0; as
Qq 5 ;; 10: len 8; hex 8000125171a21bcc; asc Qq ;; 11: len 4; hex 80000001; asc ;; 12: len 1; hex 31; asc 1;; 13: len 5; hex 576f72
473; asc Words;; 14: len 4; hex 37343338; asc 7438;; 15: len 4; hex 80004be5; asc K ;; 16: SQL NULL; 17: SQL NULL; 18: SQL NULL; 19: len 4; he
8000a2a9; asc ;; 20: len 8; hex 5030303431303537; asc P0041057;; 21: SQL NULL; 22: len 4; hex 8001595a; asc YZ;; 23: len 1; hex 80; asc
; 24: len 8; hex 8000125171a21b95; asc Qq ;; 25: len 4; hex 37343338; asc 7438;; 26: len 4; hex 80000000; asc ;; 27: SQL NULL; 28: SQL
ULL; 29: SQL NULL; 30: len 1; hex 80; asc ;; 31: SQL NULL; 32: len 1; hex 80; asc ;; 33: SQL NULL; 34: len 4; hex 00000000; asc ;; 35: SQL
NULL; 36: SQL NULL;
*** WE ROLL BACK TRANSACTION (1)
The test function is as below:
(defun fab (n)
(let ((res '(1 1)))
(loop for i from 2 to n do
(nconc res (list (+ (nth (- i 2) res) (nth (- i 1) res)))))
res))
$ecl
...
EECL (Embeddable Common-Lisp) 12.7.1 (git:UNKNOWN)
...
>(fab 10)
(1 1 2 3 5 8 13 21 34 55 89)
>(fab 20)
(1 1 2 3 5 8 13 21 34 55 89 2 3 5 8 13 21 34 55 89 144 91 5 8 13 21 34 55 89 144
Then i restart ECL
>(fab 20)
(1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 10946)
It seems the "res" is not freed after the (fac 10) ?
Sincerely!
You should use (list 1 1) rather than '(1 1) in the let form. In Common Lisp, the effects of modifying literal objects are not defined.
(defun fib (n)
(let ((res (list 1 1))) ; (list 1 1) instead of '(1 1)
(loop for i from 2 to n
do (nconc res (list (+ (nth (- i 2) res) (nth (- i 1) res)))))
res))
Constants such as '(1 1) are only allocated once by the compiler / interpreter. Your code uses NCONC on this list, modifying, and subsequent calls do no longer see the constant list '(1 1) but the modified one. In Common Lisp it is unspecified what happens when on destructively modifies constant expressions, and some implementations even protect them against changes to avoid such surprises. If you need a fresh new constant, do as people said and use (list 1 1) or avoid using NCONC altogether.