This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Show posts Menu
(inc 2.5) ; gives 3, not 3.5 as expected
(inc 2.5)
3.5
What is the ITN book?Quote from: "jopython"
Destructive functions should not be used with curry...Quote from: "Lutz"
This will be mentioned in the reference manual for 'curry' and should also be mentioned in the WikiBooks introduction.
On this simpler program:Quote from: "Lutz"
...
I cannot repeat the behavior, you are seeing (incrementing of file handles).
Quote from: "Lutz"
ps: also - unrelated - why are you using 'do-while' instead of 'while'. Shouldn't the regex test take place alwaysafterreading a line from the file?
git log -p 48317b302b67e820e8d0a9816267d5a42c68f16e
(set 'lst '(2 6 9 12))
;-> (2 6 9 12)
(inc (lst 0))
;-> 3
lst
;-> (3 6 9 12)
(map inc lst)
;-> (4 7 10 13)
(map (curry inc 3) lst)
;-> (6 9 12 15) ; === CHECK OUT THIS LINE ===
lst
;-> (3 6 9 12)
newLISP v.10.3.3 64-bit on Linux IPv4/6 UTF-8, execute 'newlisp -h' for more info.
> (set 'lst '(2 6 9 12))
(2 6 9 12)
> (inc (lst 0))
3
> lst
(3 6 9 12)
> (map inc lst)
(4 7 10 13)
> (map (curry inc 3) lst)
(6 12 21 33) ; === CHECK OUT THIS LINE ===
> lst
(3 6 9 12)
newLISP v.10.3.3 64-bit on Linux IPv4/6 UTF-8, execute 'newlisp -h' for more info.
> (set 'lst '(2 6 9 12))
(2 6 9 12)
> (map (curry inc 3) lst)
(5 11 20 32)
> lst
(2 6 9 12)
> (map (lambda (x) (+ x 3)) lst)
(5 9 12 15)
> (map (lambda (x) (inc x 3)) lst)
(5 9 12 15)
> (map (curry + 3) lst)
(5 9 12 15)
(define (read-proc-stat)
(setq procStat (open "/proc/stat" "read"))
(do-while (regex {cpud?} (read-line procStat))
(parse-stat-line (current-line)))
(close procStat))
ERR: value expected in function read-line : procStat
called from user defined function read-proc-stat
called from user defined function draw-cpu-load
(define (read-proc-stat)
(setq proc-stat (open "/proc/stat" "read"))
(println "open handle: " proc-stat)
(do-while (regex {cpud?} (read-line proc-stat))
(println (current-line)))
(close proc-stat))
(while true
(read-proc-stat)
(sleep 1000))
(define (read-proc-stat:read-proc-stat)
(if (nil? read-proc-stat:procStat)
(setq read-proc-stat:procStat (open "/proc/stat" "read")))
(do-while (regex {cpud?} (read-line read-proc-stat:procStat))
(parse-stat-line (current-line)))
(seek read-proc-stat:procStat 0))
(new Class 'Rectangle)
(new Class 'Circle)
(SomeClass:some-function) ; doesn't work on newlisp version >= v10.2
; definitions
(define (Time:Time (t (date-value)) (zone 0))
(list Time t zone))
(define (Time:show t)
(date (t 1) (t 2)))
(define (Time:days-between t1 t2)
"Return difference in days between two times."
(div (abs (- (t1 1) (t2 1))) (* 24 60 60)))
(define (Time:get-hours t)
"Return hours."
(int (date (t 1) (t 2) {%H})))
(define (Time:get-day t)
"Return day of week."
(date (t 1) (t 2) {%A}))
(define (Time:leap-year? t)
(let ((year (int (date (t 1) (t 2) {%Y}))))
(and (= 0 (% year 4))
(or (!= 0 (% year 100)) (= 0 (% year 400))))))
; use
(set 'time-now (Time))
(set 'my-birthday (Time (date-value 2008 5 26)))
(set 'christmas-day (Time (date-value 2008 12 25)))
; call functions with full context prefix
(println (Time:show christmas-day))
; or call them with colon prefix mode
(println (:show christmas-day))
$ newlisp foop.lsp
Wed Dec 24 21:00:00 2008
ERR: invalid function in function date : (MAIN:t 1)
called from user defined function Time:show
> (context Time)
Time
Time> (set 'christmas-day (Time (date-value 2008 12 25)))
(Time 1230163200 0)
Time> (:show christmas-day)
ERR: invalid function in function date : (MAIN:t 1)
called from user defined function Time:show
(define (Time:show Time:t)
(date (Time:t 1) (Time:t 2)))
$ newlisp foop.lsp
Wed Dec 24 21:00:00 2008
ERR: invalid function in function date : (t 1)
called from user defined function Time:show
Quote from: "Lutz"
The system variable$itismentioned in the 10.3.3 doc http://www.newlisp.org/downloads/newlisp_manual.html#system_symbols"> http://www.newlisp.org/downloads/newlis ... em_symbols">http://www.newlisp.org/downloads/newlisp_manual.html#system_symbols
Quote from: "Lutz"
A change in the WikiBook Introduction is not necessary.