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

#16
Anything else we might add? / -nan is not number
August 01, 2016, 01:56:39 AM
-nan (NaN) should not return true with number?



> (set 'nan (sqrt -1))
> (number? nan)
true ;; should return nil


Also advise with inf. I think all NaN and Inf are "error status" that may not throw error immediatly.

So they isn't value.
#17
I don't know how resume stack space in newLISP.



If I use one function do too much thiings, then the stack of function may occur stack overflow?



If i reject the return value when call other function, then would avoid stack overflow?



If anyone could give me some advise?
#18
ERR: call or result stack overflow in function set : term

When I see this error, I think the stack size is too small. How to enlarge it in default?
#19
When we use newlisp write code, the interpreter could not do anything for us. Because newLISP must be rapidly, more and more.



So, we could do something for to more stable code:



1. un-used symbol:



(define (foo x y) (+ x 1))


below code, symbol 'y' have not used, It's may not any dangrous. but:



(define (foo x) (+ x y))

If we use an un-declare symbol, may be occure some accident.



If we could not find below error, may enlarge error:



(define (foo x) (set 'y 10) (+ x y))

Now, all function in current Context would see this symbol, if you use this symbol, the value

may not be control by you.



all of it could not be find by newLISP interpreter, but Lint.lsp could do it.



> newlisp lint.lsp target.lsp

or you could compiler it in first.

> lint target.lsp
#20
newLISP in the real world / dangrous true?
July 27, 2016, 05:32:01 AM
if you use true? as checking function for list, be attention to: blank list -> '(), would not match it.




> (true? '())
nil



If you often use it, advise you use :



> (define (bool x) (if (nil? x) nil true))
> (for-all bool '(1 2 3 4 () 6))
#21
in newLISP, no "true" hash, is just assoc-list. I just want simulate Hash, Array use newlisp.



Just like no Hash, List and symbol in C, but Lautz could write newLISP use C.



I write Spp language implement with newLISP, it have Array, Hash, List, Rule:


> (my @array [])
[]
> (@array << :a)
[:a]
> (my %hash {1 : 2, 3 : 4})
{1 ; 2, 3 : 4}
> (%hash 1)
2
> (my @lst :(1 2 3))
(1 2 3)
#22
I re-design these two tools now:



tidy newlisp:

could find loss ")" or more ")". while, letn, dotimes all indent two space.



https://github.com/songzan/newlisp-spp/blob/master/tools/lint.lsp">https://github.com/songzan/newlisp-spp/ ... s/lint.lsp">https://github.com/songzan/newlisp-spp/blob/master/tools/lint.lsp



usage: > newlisp tidy.lsp target.lsp



lint nelisp:

could check un-declare symbol and un-used symbol.



https://github.com/songzan/newlisp-spp/blob/master/toos/lint.lsp">https://github.com/songzan/newlisp-spp/ ... s/lint.lsp">https://github.com/songzan/newlisp-spp/blob/master/toos/lint.lsp



usage: newlisp lint.lsp target.lsp



or you could puts them in your bin path:



newlisp -x lint.lsp lint
chmod 755 lint
sudo mv lint /usr/bin/lint
newlisp -x tidy.lsp tidy
chmod 755 tidy
sudo mv tidy /usr/bin/tidy
#23
I design a function model to implement "return" from any depth block.



in general, when call (return sth) in function, current function namespace would find a return value have been ready.



when return expression is in deep block, return message would be receive by main process after serval value pass.



If I use concurrent, send a message to main process, then is simply.



But send message directly to main process would destroy block stack management, if return expression is at last expression of function, restore some management variable is too waste time.



So i think, order compute is better than concurent compute in this function module.
#24
I want check a variable value till another process send it to it, then do other thing. How to design it?




(while (check-var-is-true) (do-some-thing))

#25
I need make array, hash, list use newLISP. SO i do like follows:

(define (is-blank-array x) (= x '()))

(define (is-list x) (list? x) (and (= (first x) "list") (list? (last x))))

(define (is-blank-hash x) (= x '(())))

(define (is-hash @x)
  (and (list? @x) (for-all is-pair @x)))

(define (is-pair @x)
  (and (list? @x) (= 2 (length @x)) (is-key (@x 0))))

(define (is-key @x) (or (string? @x) (number? @x)))
#26
concat two element, invoid array became list in silent

(define (concat) (apply _concat (args)))
(define (_concat @x @y)
  (cond
    ((atom? @x)
     (cond
       ((atom? @y) (cons @x @y))
       ((array? @y) (cons @x @y))
       ((list? @y) (push @y (list @x) -1))
       (true (error "error concat data"))))
    ((array? @x)
     (cond
       ((atom? @y) (cons @x @y))
       ((array? @y) (cons @x @y))
       ((list? @y) (push @x (list @y)))
       (true (error "error concat data"))))
    ((list? @x)
     (cond
       ((atom? @y) (cons @x @y))
       ((array? @y) (cons @x @y))
       ((list? @y) (list @x @y))
       (true (error "error concat data"))))
    (true (error "error concat data"))))
#27
I think array should have empty array, Just like other language.



I think "Not empty array" is a design error.
#28
When I add a array to list, then index it, it would became list in silent.



newLISP v.10.7.0 32-bit on Windows IPv4/6 libffi, options: newlisp -h

> (array? ((list 1 (array 3 '(1 2 3)) 3) 1))    
nil
> (list? ((list 1 (array 3 '(1 2 3)) 3) 1))    
true


I think array as value, when transfer to expression, it should be in definitely.



When I add a list to array, then index it, it also is list

> (list? ((array 3 '(1 (2 3) 4)) 1))
true
#29

> (empty? (array 2 '(1 2)))
ERR: list or string expected : (1 2)


I think any check function could accept any type of data.
#30
thanks, I think macro may be ok!