(*)
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 MenuBy default, we perceive an array as a special case of a list; so we expect it to act like a like in pretty much every way.Quote from: "TedWalther"
newLISP v.10.7.1 32-bit on Linux IPv4/6 UTF-8 libffi, options: newlisp -h
> (array 0)
ERR: wrong dimensions in function array : 0
>
I never managed to get quite good enough at lisp and scheme, but with newlisp I should be vaguely useful for something..Quote from: "derek"
:)
Maybe I'm doing something wrong but I can't get expand to work..Quote from: "derek"
(set 'x 2 'a '(d e)) ; from the examples
(expand '(a x(b c x) 'x 'a))
For me this just returns the first list I typed. But I'm just using this on the console, not in any macros.. is this possible??
Many thanks.
;; List Comprehensions in PYTHON
;;>>> vec = [2, 4, 6]
;;>>> [3*x for x in vec]
;;[6, 12, 18]
(set 'vec '(2 4 6))
(println (map (lambda (x) (* x 3)) vec))
;-> (6 12 18)
;;>>> vec = [2, 4, 6]
;;>>> [[x, x**2] for x in vec]
;;[[2, 4], [4, 16], [6, 36]]
(println (map (lambda (x) (list x (pow x))) vec))
;-> ((2 4) (4 16) (6 36))
;;>>> freshfruit = [' banana', ' loganberry ', 'passion fruit ']
;;>>> [weapon.strip() for weapon in freshfruit]
;;['banana', 'loganberry', 'passion fruit']
(set 'freshfruit '(" banana" " loganberry " "passion fruit "))
(println (map trim freshfruit))
;-> ("banana" "loganberry" "passion fruit")
;;>>> [3*x for x in vec if x > 3]
;;[12, 18]
;;>>> [3*x for x in vec if x < 2]
;;[]
(println (map (lambda (x) (when (> x 3)(* x 3)))vec))
;-> (nil 12 18)
(println (map (lambda (x) (when (< x 2)(* x 3))) vec))
;-> (nil nil nil)
;;>>> vec1 = [2, 4, 6]
;;>>> vec2 = [4, 3, -9]
;;>>> [x*y for x in vec1 for y in vec2]
;;[8, 6, -18, 16, 12, -36, 24, 18, -54]
(set 'vec1 '(2 4 6))
(set 'vec2 '(4 3 -9))
(dolist (x vec1)(dolist (y vec2)(print (* x y) " ")))
(println)
;-> 8 6 -18 16 12 -36 24 18 -54
;;>>> [x+y for x in vec1 for y in vec2]
;;[6, 5, -7, 8, 7, -5, 10, 9, -3]
(dolist (x vec1)(dolist (y vec2)(print (+ x y) " ")))
(println)
;-> 6 5 -7 8 7 -5 10 9 -3
;;>>> [vec1[i]*vec2[i] for i in range(len(vec1))]
;;[8, 12, -54]
(println (map * vec1 vec2))
;-> (8 12 -54)
;;>>> mat = [
;;... [1, 2, 3],
;;... [4, 5, 6],
;;... [7, 8, 9],
;;... ]
;;>>> print([[row[i] for row in mat] for i in [0, 1, 2]])
;;[[1, 4, 7], [2, 5, 8], [3, 6, 9]]
;; ou
;;>>> list(zip(*mat))
;;[(1, 4, 7), (2, 5, 8), (3, 6, 9)]
(set 'matrix '((1 2 3)(4 5 6)(7 8 9)))
(println (transpose matrix))
;-> ((1 4 7) (2 5 8) (3 6 9))
;;for i in [0, 1, 2]:
;; for row in mat:
;; print(row[i], end="")
;; print()
(dolist (row (transpose matrix)) (println row))
;-> (1 4 7)
; (2 5 8)
; (3 6 9)
Hi everybody !Quote from: "Ormente"
I'm a new newLISPer from France, and very happy to have found thispragmatic LISP.
newLISP v.10.1.5 on Win32 IPv4, execute 'newlisp -h' for more info.Quote
> (directory? "c:")
ERR: string token too long : "c:")rn"
> (directory? "c:\")
nil
> (directory? {c:})
nil
> (directory? {c:\})
true
>
> (directory? "c:/")Quote
nil
> (directory? "")
ERR: string token too long : "")rn"
> (directory? "\")
nil
> (directory? "\.")
true
> (directory? "/.")
true
>
newLISP v.10.1.1 on Win32 IPv4, execute 'newlisp -h' for more info.
> (context 'NEWCTX)
NEWCTX
NEWCTX> (set '$myvar 123)
123
NEWCTX> (context MAIN)
MAIN
> $myvar
123
> NEWCTX:$myvar
nil
>
newLISP v.10.1.1 on Win32 IPv4, execute 'newlisp -h' for more info.
> (setq NEWCTX:$myvar 123)
123
> $myvar
nil
> NEWCTX:$myvar
123
>
Quote from: "ale870"
I like map usage for multiple assignment!
newLISP v.10.0.6 on Win32 IPv4, execute 'newlisp -h' for more info.
> (map set '(a b c d e f) '(1 2 3 4 5 6))
(1 2 3 4 5 6)
> (map set '(a b c d e f) (list b c a e f d))
(2 3 1 5 6 4)
>
Quote from: "DekuDekuplex"
Apparently, carriage returns typed within the REPL in newLISP-GS are not being processed properly;viz.:
In the newLISP command prompt REPL, outside the IDE:
newLISP v.10.0.1 on Win32 IPv4, execute 'newlisp -h' for more info.
> [cmd]
1
[/cmd]
1
>
In the newLISP-GS REPL, inside the IDE:
> [cmd]
1
[/cmd]
nil
1
nil
1
>
-- Benjamin L. Russell