Search found 156 matches

by newBert
Tue Jul 06, 2021 1:30 pm
Forum: Whither newLISP?
Topic: loop & recur
Replies: 2
Views: 735

Re: loop & recur

I really like NewLISP and yet I miss the optimised terminal recursion too. I'm interested in your macro, which I'm currently testing. It seems a bit slower than the 'trampolines' (just an impression, not verified), but it is much easier to use, and also more elegant. Obviously, an iterative loop wil...
by newBert
Fri Apr 30, 2021 9:26 am
Forum: newLISP in the real world
Topic: Code Lisp-ish enough??
Replies: 2
Views: 1173

Re: Code Lisp-ish enough??

I tried this, unpretentious: https://controlc.com/10370640

(Sorry ! Impossible to paste code here, because of "internal server error")
by newBert
Thu Apr 29, 2021 1:35 pm
Forum: newLISP in the real world
Topic: Create a function with a function
Replies: 7
Views: 1674

Re: Create a function with a function

Sorry, I could not indent the previous code, because it caused an "internal server error" (?!)
by newBert
Thu Apr 29, 2021 1:31 pm
Forum: newLISP in the real world
Topic: Create a function with a function
Replies: 7
Views: 1674

Re: Create a function with a function

So, maybe like this (probably improvable):

Code: Select all

(define-macro (make-adder) (local (name val) (bind (args) true) (set (expand name 'name) (expand (lambda (x) (+ val x)) 'val))))

(make-adder (name 'add10) (val 10))
(println (add10 3))
; 13
by newBert
Tue Apr 27, 2021 5:15 pm
Forum: newLISP in the real world
Topic: Create a function with a function
Replies: 7
Views: 1674

Re: Create a function with a function

Oh my apologies! I reversed x and y (in `letex`) when transcribing... :/

Code: Select all

(define (make-adder x)
  (letex (y x)
    (fn (z) (+ y z))))
    
(setq add2 (make-adder 2))
(println (add2 4))
; 6
by newBert
Mon Apr 26, 2021 9:02 am
Forum: newLISP in the real world
Topic: Create a function with a function
Replies: 7
Views: 1674

Re: Create a function with a function

Maybe this way, but it's not quite the same:

Code: Select all

(define (make-adder x)
  (letex (x y)
    (fn (z) (+ y z))))
    
(setq add2 (make-adder 2))
(println (add2 4))
> 6
by newBert
Mon Feb 01, 2021 5:31 pm
Forum: newLISP Graphics & Sound
Topic: Running "allegro game library" within NewLisp?
Replies: 1
Views: 3009

Re: Running "allegro game library" within NewLisp?

First, you need to understand how the function import works. And see some examples where it is used, like here for instance (see especially the first part with the 'import' and the 'constant' ). Then after recovering all the functions from Allegro , the rest is a work of patience, a little repetitiv...
by newBert
Wed Sep 02, 2020 10:14 am
Forum: newLISP in the real world
Topic: using ref data
Replies: 5
Views: 2427

Re: using ref data

cameyo wrote:
Wed Sep 02, 2020 7:34 am
the "ref-all" and "ref" functions have a parameter to get data instead of indexes.
Well seen ! I had completely forgotten this option.
Thanks, Cameyo.
by newBert
Mon Aug 31, 2020 1:38 pm
Forum: newLISP in the real world
Topic: using ref data
Replies: 5
Views: 2427

Re: using ref data

Sorry, I don't have time to answer from a concrete example that should first be created. But I think there are some interesting tracks in the wikibook, especially here (see 'find-all' at the end).
by newBert
Mon Aug 31, 2020 1:16 pm
Forum: newLISP in the real world
Topic: how to prevent unwanted eval?
Replies: 1
Views: 1183

Re: how to prevent unwanted eval?

One possibility, probably among others: > (define (g (x nil)) x) (lambda ((x nil)) x) > (define-macro (f) (setf (nth '(0 0 1) g) (args 0))) (lambda-macro () (setf (nth '(0 0 1) g) (args 0))) > (f 1) 1 > (g) 1 > (f '(+ 1 2)) '(+ 1 2) > (g) (+ 1 2) P.S. : I preferred (args 0) instead of 'data' for mac...
by newBert
Fri Aug 28, 2020 10:21 am
Forum: newLISP in the real world
Topic: Setup functions by setq
Replies: 1
Views: 1207

Re: Setup functions by setq

lyl wrote:
Fri Aug 28, 2020 5:54 am

Code: Select all

(setq a '(a1 a2))
(dolist (x a)
  (let (z $idx)
    (setq x (lambda(y) z))
    ))
What's wrong with my code, and how to solve it?
Maybe with :

Code: Select all

(dolist (x a)
  (let (z $idx)
    (set (sym x) (expand (lambda (y) z) 'z))))
by newBert
Fri Jul 03, 2020 1:22 pm
Forum: newLISP in the real world
Topic: Sum of integers in a string
Replies: 7
Views: 2830

Re: Sum of integers in a string

cameyo wrote:
Fri Jul 03, 2020 10:26 am
thank you. I learned new things.
You're welcome! I learned new things too... :)
by newBert
Thu Jul 02, 2020 12:02 pm
Forum: newLISP in the real world
Topic: Sum of integers in a string
Replies: 7
Views: 2830

Re: Sum of integers in a string

In this case we could also do:

Code: Select all

> (apply + (map (fn (x) (int (if (starts-with x "0") (rest x) x))) (find-all {[0-9]+} "o123p010iru5")))
138
by newBert
Mon May 25, 2020 11:01 am
Forum: newLISP in the real world
Topic: From "The Little Schemer" to newLISP
Replies: 2
Views: 1621

Re: From "The Little Schemer" to newLISP

I think the definition of ‘rember-f’ is wrong. A correct writing of this lambda would be : (define rember-f (lambda (test? a l) (cond ((null? l) '()) ((test? (first l) a) (rest l)) (true (cons (first l) (rember-f test? a (rest l))))))) > (rember-f = 'tuna '(shrimp salad and tuna salad)) (shrimp sala...
by newBert
Mon May 25, 2020 9:04 am
Forum: newLISP in the real world
Topic: Parallel assignment
Replies: 3
Views: 1782

Re: Parallel assignment

Yes, map is a very useful function which works well in parallel.
It is handy too to take the place of ‘list comprehensions’...
by newBert
Mon May 25, 2020 8:43 am
Forum: newLISP in the real world
Topic: Parallel assignment
Replies: 3
Views: 1782

Re: Parallel assignment

Just another way to do it (with what comes to hand):

Code: Select all

> (setq x 2 y 3)
3
> (map set '(x y) (list (+ 1 y) (+ 1 x)))
(4 3)

> (setq x 1 y 2 z 3)
3
> (map set '(x y z) (list (+ x y z) (- z y x) (- x y z)))
(6 0 -4)
 
:)
by newBert
Sun May 24, 2020 5:57 pm
Forum: newLISP in the real world
Topic: How to determine whether a list can be evaluated
Replies: 2
Views: 1975

Re: How to determine whether a list can be evaluated

My quesstion is: Is there an universal method to determine whether a list can be evaluated or not? Oops ! Why didn't I think of catch ? > (setq a '(1 2 3)) (1 2 3) > (catch (eval a) 'result) nil ; `a` can't be evaluated (see error below in `result`) > result "ERR: illegal parameter type in function...
by newBert
Sun May 24, 2020 10:19 am
Forum: newLISP Graphics & Sound
Topic: Combo-box
Replies: 1
Views: 3259

Re: Combo-box

Sorry for the late answer, but the forum was inaccessible for a moment.
I think the solution is in “widgets-demo.lsp”.
Maybe you should use ‘base64-dec’ to decode the value of combo-box.
by newBert
Sat Jul 13, 2019 9:08 am
Forum: newLISP in the real world
Topic: How to determine whether a list can be evaluated
Replies: 2
Views: 1975

Re: How to determine whether a list can be evaluated

(setq a '(1 2 3)) ;; This list can not be evaled It's normal, because ‘1’ is neither a primitive nor a lambda (setq b '(1 a)) ;; This list can be evaled, (eval b) --> (2 3) Also normal, because (1 a) is equivalent to (rest a) <- implicit indexing (setq c '(+ 1 2)) ;; This list can be evaled, (eval ...
by newBert
Thu Mar 07, 2019 5:33 pm
Forum: newLISP in the real world
Topic: let and letn
Replies: 4
Views: 2380

Re: let and letn [resolved]

Indeed, I've just tried again now, in a new NewLISP session, and I get the expected result: (1 2 3 (4 5 6 7) (nil nil nil nil)) . I'm reassured :). Thank you , RalphRonnquist, Cameyo and Rickyboy for your replies and advice. I don't know what could have happened... I probably forgot NewLISP has no l...
by newBert
Mon Mar 04, 2019 1:30 pm
Forum: newLISP in the real world
Topic: let and letn
Replies: 4
Views: 2380

let and letn

I don't understand why letn isn't required here, or why let doesn't cause an error:

Code: Select all

(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)))
;−> (1 2 3 (4 5 6 7) (1 2 3 4 5 6 7))
by newBert
Mon Mar 04, 2019 12:18 pm
Forum: newLISP in the real world
Topic: list of functions question
Replies: 3
Views: 2069

Re: list of functions question

(With some delay...)
I think we could also write: (set 'funclist (list myfunc myfunc myfunc myfunc myfunc)), so we don't need ‘eval’ in (set 'afunc (funclist 2))
by newBert
Sat Dec 22, 2018 12:36 pm
Forum: newLISP in the real world
Topic: anti-select elements of a list
Replies: 9
Views: 3420

Re: anti-select elements of a list

Here is a solution (probably not the only one, nor the best) : newLISP v.10.7.5 64-bit on Linux IPv4/6 UTF-8 libffi, options: newlisp -h > (select '(0 1 2 3 4) (difference (index true? '(0 1 2 3 4)) '(1 2))) (0 3 4) > ;; maybe clearer: > (let (lst '(0 1 2 3 4)) (select lst (difference (index true? ...
by newBert
Fri Dec 21, 2018 10:37 am
Forum: newLISP in the real world
Topic: anti-select elements of a list
Replies: 9
Views: 3420

Re: anti-select elements of a list

Here is a solution (probably not the only one, nor the best) : newLISP v.10.7.5 64-bit on Linux IPv4/6 UTF-8 libffi, options: newlisp -h > (select '(0 1 2 3 4) (difference (index true? '(0 1 2 3 4)) '(1 2))) (0 3 4) > ;; maybe clearer: > (let (lst '(0 1 2 3 4)) (select lst (difference (index true? l...
by newBert
Sat Oct 27, 2018 4:44 pm
Forum: newLISP in the real world
Topic: FUNCALL and GETDEF
Replies: 3
Views: 2296

Re: FUNCALL and GETDEF

Hi newbert, I have found these functions in an old article on Lisp (to define a function it use DE, maybe Portable Standard Lisp). GETDEF gets the definition of a function. Thanks for infos. A Function in newLISP is not a "closure", so we can examine its content typing its name without parentheses ...