Another newLISP-like language :)

Started by cormullion, January 29, 2008, 11:24:07 PM

Previous topic - Next topic

Elica

#45
AFAICU (as far as I can understand)
(define-macro (memoize func mem-func) ...)
defines a memoizational version of a function.



As always I am curious. My question is whether it is possible to define something like:
(define-macro (memoize func) ...)
(define-macro (dememoize func) ...)

thus you can set a function to become memoizational without creating a new function. By reusing the same name if you have some user code it will start to work with the memoized function without change in the source.



And for symmetry, the dememoization means to recover the original function.

newBert

#46
Quote from: "Fanda"My expectations were quite high, but there are some good things to look at ;-)



I believe that for example Clojure innovates more:

http://clojure.sourceforge.net/">http://clojure.sourceforge.net/



Fanda


Some Clojure/NewLISP comparisons :
;;; Clojure ;;;
;user=> (def x 5)
;user=> (def lst '(a b c))
;user=> `(fred x ~x lst ~@lst 7 8 :nine)
;  (user/fred user/x 5 user/lst a b c 7 8 :nine)
;;;

(set 'x 5)
(set 'lst '(a b c))
(println (flat (list 'fred 'x x 'lst lst 7 8 'nine)))

;;; CloJure ;;;
; (let
; [[a b c & d :as e] [1 2 3 4 5 6 7]]
; [a b c d e])
;
; => [1 2 3 (4 5 6 7) [1 2 3 4 5 6 7]]
;;;

(bind (map list '(a b c d e) '(1 2 3 (4 5 6 7) (1 2 3 4 5 6 7))))
(println (list a b c d e))

(local (a b c d e)
(map set '(a b c) '(1 2 3))
(set 'd '(4 5 6 7))
(set 'e (flat (list a b c d)))
(println (list a b c d e)))

(let (a 1 b 2 c 3 d '(4 5 6 7) e (flat (list a b c d)))
(println (list a b c d e)))

;;; CloJure ;;;
; (let
; [vec [1 2 3 4]
; map {:fred "ethel"}
; lst (list 4 3 2 1)]
; (list
; (conj vec 5)
; (assoc map :ricky "lucy")
; (conj lst 5)
; ; the original are intact
; vec
; map
; lst))
; => ([1 2 3 4 5] {:ricky "lucy", :fred "ethel"} (5 4 3 2 1) [1 2 3 4] {:fred "ethel"} (4 3 2 1))
;;;

(let
(vec (array 4 '(1 2 3 4))
asso (list '(fred "ethel"))
lst '(4 3 2 1))
(println (list
(append vec (array 1 '(5)))
(append asso (list '(ricky "lucy")))
(append '(5) lst)
; the original are intact
vec
asso
lst)))

;;; CloJure ;;;
; ;cycle produces an 'infinite' seq
; (take 15 (cycle [1 2 3 4]))
; => (1 2 3 4 1 2 3 4 1 2 3 4 1 2 3)
;;;

(println (array 15 (sequence 1 4)))

;;; CloJure ;;;
; (defn my-zipmap [keys vals]
; (loop
; [map {}
; ks (seq keys)
; vs (seq vals)]
; (if (and ks vs)
; (recur (assoc map (first ks) (first vs))
; (rest ks)
; (rest vs))
; map)))
;
; (my-zipmap [:a :b :c] [1 2 3])
; => (:b 2, :c 3, :a 1)
;;;

(println (map list '(a b c) '(1 2 3)))


;;; CloJure ;;;
; (re-seq #"[0-9]+" "abc123def345ghi567")
; => ["123" "345" "567"]
;
; (re-find #"([-+]?[0-9]+)/([0-9]+)" "22/7")
; => ["22/7" "22" "7"]
;;;

(println (find-all "[0-9]+" "abc123def345ghi567"))

(println (regex "([-+]?[0-9]+)/([0-9]+)" "22/7"))

;;; CloJure ;;;
;; Mutual recursion example
;
;; forward declaration
;(def even?)
;
;; define odd in terms of 0 or even
;(defn odd? [n]
;  (if (zero? n)
;      false
;     (even? (dec n))))
;
;; define even? in terms of 0 or odd
;(defn even? [n]
;  (if (zero? n)
;      true
;      (odd? (dec n))))
;
;(even? 3)
;=> false
;;;

(define (odd? n)
(if (zero? n)
nil
(even? (dec 'n))))

(define (even? n)
(if (zero? n)
true
(odd? (dec 'n))))

(println (even? 3)) ;=> nil

;;; Clojure ;;;
; (defn argcount
; ([] 0)
; ([x] 1)
; ([x y] 2)
; ([x y & more] (+ (argcount x y) (count more))))
;
; (argcount) => 0
; (argcount 1) => 1
; (argcount 1 2) => 2
; (argcount 1 2 3 4 5) => 5
;;;

(define (argcount)
(case (length (args))
(0 0)
(1 1)
(2 2)
(true (length (args)))))
;or   (true (+ (argcount (args 0) (args 1)) (length (2 (args)))))

(println (argcount))           ; => 0
(println (argcount 1))         ; => 1
(println (argcount 1 2))       ; => 2
(println (argcount 1 2 3 4 5)) ; => 5
etc., etc.



No comments, except that I do not like the use of [] and {} in CloJure.

NewLISP seems to me easier, simpler and more consistent



Regards,

Bertrand

The crazy tester struck again ;)
<r><I>>Bertrand<e></e></I> − <COLOR color=\"#808080\">><B>newLISP<e></e></B> v.10.7.6 64-bit <B>>on Linux<e></e></B> (<I>>Linux Mint 20.1<e></e></I>)<e></e></COLOR></r>

cormullion

#47
That's very informative - there's nothing like seeing the two side by side to get a feeling for the fundamental style of the languages.

lithper

#48
Quote from: "newBert"
Quote from: "Fanda"My expectations were quite high, but there are some good things to look at ;-)



I believe that for example Clojure innovates more:

http://clojure.sourceforge.net/">http://clojure.sourceforge.net/

Fanda

Some Clojure/NewLISP comparisons :


I do not quite understand, though: how can one compare a dialect of lisp, written on top of JVM, and allowing easy importation of Java libraries into the lisp code/framework --- and a dialect of lisp, written in C and allowing a very simple importation from any libraries in C ?!!



It's obvious that the second one is preferrable and will win by a huge margin, as Java is slow. Java is as slow as the "big Lisps" are,  and even more in actual practice, see comparisons here:

http://www.flownet.com/gat/papers/lisp-java.pdf">http://www.flownet.com/gat/papers/lisp-java.pdf

and discussion of comparison tests here:

http://www.alh.net/newlisp/phpbb/viewtopic.php?p=12050&highlight=#12050">http://www.alh.net/newlisp/phpbb/viewto ... ght=#12050">http://www.alh.net/newlisp/phpbb/viewtopic.php?p=12050&highlight=#12050



Especially in view of the fact that NewLISP exists on all platforms, or almost, is roughly 200kB, and can create fully standalone tiny programs without dependencies, so allowing cardinally new solutions (many tiny fully-featured standalones) in lots of cases?!



Why even talk about CJ, even if it might be an interesting toy to play with and compare how two different desiners took their decisions when developing these lisps..

newBert

#49
QuoteI do not quite understand, though: how can one compare a dialect of lisp, written on top of JVM, and allowing easy importation of Java libraries into the lisp code/framework --- and a dialect of lisp, written in C and allowing a very simple importation from any libraries in C ?!!

It was just about a stylistic composition, just to see how we could make finally the same thing  with NewLISP :)



It allowed me to use NewLISP functions which I did not still have to investigate so far ... I learnt new things on NewLISP by misleading me a little towards other horizons ;)



Now I know that NewLISP is not comparable to Clojure because I practised a little the latter. I prefer to check for myself rather than give credit to prejudices.



And then I like to test, compare, browse :D



Curiosity is not just a nasty fault.



I do the same thing with CLisp, Scheme, Python vs NewLISP and I discover full of interesting things and ideas.


QuoteWhy even talk about CJ, even if it might be an interesting toy to play with and compare how two different desiners took their decisions when developing these lisps..
... just to highlight NewLISP ;)
<r><I>>Bertrand<e></e></I> − <COLOR color=\"#808080\">><B>newLISP<e></e></B> v.10.7.6 64-bit <B>>on Linux<e></e></B> (<I>>Linux Mint 20.1<e></e></I>)<e></e></COLOR></r>