Search found 58 matches
- Mon Oct 07, 2013 4:44 am
- Forum: Whither newLISP?
- Topic: lexical-let
- Replies: 2
- Views: 6505
lexical-let
Before version 24.1, EMACS Lisp was dynamically scoped; now lexical scoping is an option. When a closure was needed, it was customary to load the CL package and use lexical-let. It would be very nice if lexical-let were added to newLISP. Closures could be created more easily, by a method that is mor...
- Sun Oct 06, 2013 7:50 am
- Forum: newLISP in the real world
- Topic: rewrite macros for updating association-lists
- Replies: 1
- Views: 1631
rewrite macros for updating association-lists
(macro (assoc-push Alist Key Val) (let (key Key val Val) (or (catch (push val (or (lookup key Alist) (throw nil)) -1)) (push (list key (list val)) Alist -1)))) (macro (assoc++ Alist Key Val) (let (key Key val Val) (or (catch (++ (or (lookup key Alist) (throw nil)) (or val 1))) (push (list key (or v...
- Fri Dec 28, 2012 8:53 pm
- Forum: newLISP in the real world
- Topic: Possible bug in sort
- Replies: 4
- Views: 2321
Re: Possible bug in sort
I just tested the speed using Lutz's 'fun workaround. The composed function is just as fast as the lambda (fn (a b) (< (last a) (last b))) . Perhaps I should explain the name f<g= . If I remember correctly, J (descended from APL) gives names to its operators that compose functions like fork, atop, c...
- Fri Dec 28, 2012 8:07 pm
- Forum: newLISP in the real world
- Topic: Possible bug in sort
- Replies: 4
- Views: 2321
Re: Possible bug in sort
Thanks for the fast and helpful reply.
Function composition is a powerful and fun technique.
I'm hoping that
won't be slower than
Function composition is a powerful and fun technique.
I'm hoping that
Code: Select all
(sort (copy test-list) (f<g= < last))
Code: Select all
(sort (copy test-list) (fn (a b) (< (last a) (last b))))
- Fri Dec 28, 2012 5:08 pm
- Forum: newLISP in the real world
- Topic: Possible bug in sort
- Replies: 4
- Views: 2321
Possible bug in sort
;; Function composition. (define (f<g= f g) (expand (fn (a b) (f (g a) (g b))) 'f 'g)) ((f<g= < last) '(a 2) '(b 3)) ==> true ((f<g= < last) '(b 3) '(a 2)) ==> nil (set 'lst '((b 5) (a 2))) (sort lst (f<g= < last)) ==> ((a 2) (b 5)) (set 'lst '((a 2) (b 5))) (sort lst (f<g= < last)) ==> ((a 2) (b 5...
- Thu Dec 27, 2012 12:12 pm
- Forum: Anything else we might add?
- Topic: wish i could enter multiline expressions by default
- Replies: 10
- Views: 6454
Re: wish i could enter multiline expressions by default
Here's a REPL that I cobbled together. It probably has bugs, but it works pretty well for me. (println "Quit with (exit).") (define (input__complete? str) (if (or (find "^\s*$" str 0) (find "^\s*;[^\n]*$" str 0)) true (let (error-message "" scanned 0) (if (catch (begin (read-expr str) (setq scanned ...
- Fri Dec 21, 2012 3:33 pm
- Forum: newLISP in the real world
- Topic: Is there an equivalent to flet or labels?
- Replies: 7
- Views: 3534
Re: Is there an equivalent to flet or labels?
Code: Select all
> (set 'a (fn (n) (if (zero? n) 1 (* n (a (- n 1))))))
(lambda (n)
(if (zero? n)
1
(* n (a (- n 1)))))
> (a 5)
120
- Fri Dec 21, 2012 3:11 pm
- Forum: newLISP in the real world
- Topic: list to values
- Replies: 4
- Views: 2476
Re: list to values
Code: Select all
(define (my-func s1 s2 a b c)
(dup (string s1 s2 a b) c))
> (my-func "o" "-" 1984 9 3)
"o-19849o-19849o-19849"
> (apply my-func (cons "o" (cons "-" '(1984 9 3))))
"o-19849o-19849o-19849"
> (apply my-func (append '("o" "-") '(1984 9 3)))
"o-19849o-19849o-19849"
- Fri Dec 21, 2012 2:47 pm
- Forum: newLISP in the real world
- Topic: Use map to process list of lines from stdin?
- Replies: 4
- Views: 2846
Re: Use map to process list of lines from stdin?
Code: Select all
(define (half-string str)
((div (length str) 2) str))
(while (read-line)
(println (half-string (current-line))))
- Tue Apr 10, 2012 5:03 pm
- Forum: newLISP in the real world
- Topic: Pseudo-closures using gensym
- Replies: 5
- Views: 2940
Re: Pseudo-closures using gensym
It seems that gensym isn't really needed anymore.
One can simply do (sym (uuid)).
One can simply do (sym (uuid)).
- Mon Apr 09, 2012 10:52 pm
- Forum: Anything else we might add?
- Topic: escaping characters problem
- Replies: 10
- Views: 8189
Re: escaping characters problem
I'm processing some text so that various characters are replaced with alternative formulations. The problem is that the curly braces in the original text need to be replaced with \letteropenbrace{} but the backslashes need to be replaced with \letterbackslash{}, and I can't do both these operations...
- Sun Apr 08, 2012 11:05 pm
- Forum: newLISP in the real world
- Topic: Some minor errors about manual and ....
- Replies: 7
- Views: 3615
Re: Some minor errors about manual and ....
Code: Select all
;; using sym for simulating hash tables
(set (sym "John Doe" 'MyDB') 1.234)
- Sun Apr 08, 2012 12:28 am
- Forum: newLISP in the real world
- Topic: Macros for pipelining
- Replies: 2
- Views: 2007
Re: Macros for pipelining
Interesting approach; I'm not very familiar with letex. Since we are putting each macro in its own context, I think you can safely use func instead of _func. I like "(if $args" instead of "(if (empty? (args))"; shorter and cleaner. You gave me the idea of just using one eval : (context '->>) (define...
- Sat Apr 07, 2012 4:35 pm
- Forum: newLISP in the real world
- Topic: Macros for pipelining
- Replies: 2
- Views: 2007
Macros for pipelining
Here are two "threading" or pipelining macros, similar to those in Clojure: (context '->>) (define-macro (->>:->> E form) (if (empty? (args)) (if (list? form) (eval (push E form -1)) (eval (list form E))) (eval (cons '->> (cons (list '->> E form) (args)))))) (context '->) (define-macro (->:-> E form...
- Sat Apr 07, 2012 1:52 pm
- Forum: newLISP in the real world
- Topic: Yet another REPL
- Replies: 1
- Views: 1449
Re: Yet another REPL
Slightly improved. To quit, type "(exit)". (define (input__complete? str) (if (or (find "^\s*$" str 0) (find "^\s*;[^\n]*$" str 0)) true (let (error-message "" scanned 0) (if (catch (begin (read-expr str) (setq scanned $0)) 'error-message) (input__complete? (slice str scanned)) (when (find {^ERR: sy...
- Wed Apr 04, 2012 10:17 pm
- Forum: newLISP in the real world
- Topic: Yet another REPL
- Replies: 1
- Views: 1449
Yet another REPL
Allows you to spread your expressions over several lines. : ( factor 99999999991 ) (83 1289 934693) If botched input keeps the prompt from appearing, control-Z (under Windows; for Linux, try control-D) should clear up the problem: : * 2 3) ) ) ^Z ERR: string expected : nil A work in progress. Modify...
- Wed Apr 04, 2012 8:49 pm
- Forum: newLISP in the real world
- Topic: Pseudo-closures using gensym
- Replies: 5
- Views: 2940
Re: Pseudo-closures using gensym
Thanks. I think it would be nice if gensym were built into newLISP.
- Wed Apr 04, 2012 2:22 pm
- Forum: newLISP in the real world
- Topic: Pseudo-closures using gensym
- Replies: 5
- Views: 2940
Re: Pseudo-closures using gensym
Slightly improved, and with an example in which two lambdas share a variable. (define-macro (closure varval-pairs) (let (body (cons 'begin (args)) alist (map (fn(x) (list (x 0) (gensym) (eval (x 1)))) (explode varval-pairs 2))) (bind (map (fn (x) (rest x)) alist)) (dolist (x alist) (set-ref-all (x 0...
- Sun Apr 01, 2012 3:39 pm
- Forum: newLISP in the real world
- Topic: Pseudo-closures using gensym
- Replies: 5
- Views: 2940
Pseudo-closures using gensym
(define (gensym:gensym) (sym (string "gensym-" (inc gensym:counter)))) (define-macro (closure varval-pairs body) (let (alist (map (fn(x) (list (x 0) (gensym) (eval (x 1)))) (explode varval-pairs 2))) (bind (map (fn (x) (rest x)) alist)) (dolist (x alist) (set-ref-all (x 0) body (x 1))) body)) (set ...
- Fri Mar 09, 2012 1:59 am
- Forum: newLISP in the real world
- Topic: Set Operations
- Replies: 4
- Views: 2685
Re: Set Operations
Good news, Kazimir. Lutz sent me a p.m. indicating that this will be added.Kazimir Majorinc wrote:I agree about union, not because it is particularly missing, but because it is low hanging fruit.
- Thu Mar 08, 2012 2:45 am
- Forum: newLISP in the real world
- Topic: dolist but getting more values at the same time
- Replies: 18
- Views: 6579
Re: dolist but getting more values at the same time
I enjoy using the int-reduce option in apply.
When int-reduce is 2, the behavior is like fold or reduce; when it's larger than 2, it's even more fun.
When int-reduce is 2, the behavior is like fold or reduce; when it's larger than 2, it's even more fun.
Code: Select all
> (apply (fn(_ a b c)(println a b c)) (cons nil (sequence 1 9)) 4)
123
456
789
- Wed Mar 07, 2012 9:13 pm
- Forum: Whither newLISP?
- Topic: extract analogous to extend?
- Replies: 6
- Views: 9049
Re: extract analogous to extend?
Yes, I later realized that. My post has been corrected.rickyboy wrote:Don't know about Scheme, but in SBCL:Code: Select all
* (mapc #'set '(ee ff gg) '(22 33 44)) (EE FF GG) * ee 22 * ff 33 * gg 44
- Wed Mar 07, 2012 10:12 am
- Forum: Whither newLISP?
- Topic: extract analogous to extend?
- Replies: 6
- Views: 9049
Re: extract analogous to extend?
I never thought of
... probably because it's not allowed in other languages.
Gambit Scheme:
Code: Select all
(map set '(a b c) '(1 2 3))
Gambit Scheme:
Code: Select all
4> (map define '(ee ff gg) '(22 33 44))
*** ERROR IN (console)@8.6 -- Macro name can't be used as a variable: define
- Tue Mar 06, 2012 9:30 am
- Forum: Anything else we might add?
- Topic: all? or perhaps predicates that accept multiple args
- Replies: 4
- Views: 4099
Re: all? or perhaps predicates that accept multiple args
This works for me:
Code: Select all
(define (for-all-args func)
(for-all func (args)))
> (for-all-args number? 2 3 4 5)
true
> (for-all-args number? 2 3 'not 5)
nil
- Tue Mar 06, 2012 6:52 am
- Forum: newLISP in the real world
- Topic: Function composition?
- Replies: 4
- Views: 2804
Re: Function composition?
These seem to work. ;; Compose two functions. Both accept only 1 argument. (define (atop f g) (expand (lambda (a) (f (g a))) 'f 'g)) ;; Compose two functions. The first to be called accepts ;; any number of arguments. (define (atop* f g) (expand (lambda () (f (apply g (args)))) 'f 'g)) Thanks to Kaz...