Menu

Show posts

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

Messages - ssqq

#1
When `rest` or `chop` or `filter` a list, empty list would be create.

But many function that process list would throw error with empty list (first last rest nth).

So newlisper need treate empty list as special list to avoid code crash.



If index empty list return nil, then would simplify coding processing list.



(set '@lst (process @lst))
(cond
   ((symbol? (first @lst) (dosth ..))
   (true ..))
#2
I think newlisp treat `,` and follow args as extra args, so assign them with nil in default and init in *args stack*.
#3

> (define (show-args) (println (args)))            
(lambda () (println (args)))                        
> (show-args 1 2 3)                                
(1 2 3)                                            
(1 2 3)                                            
> (define (show-args,@x) (println (args)))          
(lambda (, @x) (println (args)))                    
> (show-args 1 2 3)                                
(3)                                                
(3)                                                
> (define (show-args @x, @y) (println @x (args)))  
(lambda (@x , @y) (println @x (args)))              
> (show-args 1 2 3)                                
1()                                                
()                                                  
>
#4
I have not use process, because switch at Windows and Ubuntu.
#5
Anything else we might add? / Re: Strange reader
September 02, 2016, 09:00:57 PM
Now follow expr is ok:



> (sym "fn")
fn
> (sym "lambda")
lambda
> (sym "lambda-macro")
lambda-macro

> (lambda? (cons (sym "fn")))
nil
;; but get lambda exprssion in dynamically is not ok
> (lambda? (eval (cons (sym "fn"))))
ERR: invalid function : (fn)

#6
Anything else we might add? / case design
August 22, 2016, 07:12:05 AM

(constant 'Type 1)

(define (check-type x)
  (case
    (Type (println "it is Type"))
    (true (println "it is not Type"))))

(check-name 1)

(exit)

==> it is not Type



For: case

syntax: (case exp-switch (exp-1 body-1) [(exp-2 body-2) ... ])



The result of evaluating exp-switch is compared to each of the[size=150] unevaluated [/size]expressions exp-1, exp-2,



I want to know Why make case expression with unevaluated?
#7
I found my stack over flow is code design have problem, when call a function with recursive over 50> times, would occur this error.



> (define (call x) (cond ((= x 1) x) (true (dec x) (+ x (call x)))))
> (call 1000)
ERROR: stack over flow
#8
newLISP in the real world / Re: intersect bug?
August 05, 2016, 01:04:51 AM
Quote
intersect

syntax: (intersect list-A list-B)

syntax: (intersect list-A list-B bool)


If you want intersect more list:



> (set '@lst '((1 2 3 4) (2 3 4 5) (3 4 5 6) (4 5 6 7)))
((1 2 3 4) (2 3 4 5) (3 4 5 6) (4 5 6 7))
> (map (curry apply intersect) (explode @lst 2))
((2 3 4) (4 5 6))
> (apply intersect (map (curry apply intersect) (explode @lst 2)))
(4)

#9
I could not run this code:
Quote
combinations (2 2) 1 ():list level 0

extend yields list? true

combinations (2) 1 (2):list level 1

extend yields list? true

combinations () 1 (2):list level 1

combinations (2 2) 2 ():list level 0

extend yields list? combinations () 2 (2 2):list level 2

true

combinations (2) 2 (2):list level 1

extend yields list? true

combinations () 2 (2 2):list level 2

extend yields list?

ERR: list expected : (combinations ((+ 1 $idx) n) k (append r (list x)) true (+ 1 lvl))

called from user function (combinations lst j)

called from user function (all-factors (factor i))

called from user function (antiprime)


#10

> (define (ex @x) (extend "a" @x))
(lambda (@x) (extend "a" @x))
> (map ex (explode "abc"))
("aa" "aab" "aabc")
#11
But if code is in file, it is OK.



ssqq@X61:~/spp-newlisp$ cat debug.lsp
(constant 'say println)

(define (regex-str-char @str)
  (replace {([Q()[]{}|.+*?^$E])} @str (string {} $1) 0))

(say (regex-str-char "{}()"))

(exit)
ssqq@X61:~/spp-newlisp$ newlisp debug.lsp
{}()

#12

> {[Q{E]}
ERR: string token too long : "[\Q{\E]}"
> {[Q{E]}
ERR: string token too long : "[\Q\{\E]}"
#13

> {[{]}

ERR: string token too long : "[{]}"
> {[{]}

ERR: string token too long : "[\{]}"
;; nnn also could not recognize in {..}
> {123}
"\123"

#14
Anything else we might add? / Re: -nan is not number
August 02, 2016, 07:40:45 AM
I see, Reason is ANSI C could not support.
#15
4: 2

ERR: invalid function in function if : (prime? f)

called from user function (antiprime)



"extend" would treat first argument as place and Increase by degress,you'd better use cons or other ...