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 - newBert

#1
Whither newLISP? / Re: loop & recur
July 06, 2021, 06:30:04 AM
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 will always be more efficient, but it can be frustrating when our reasoning is definitely conditioned by Lisp or Scheme. :)
#2
I tried this, unpretentious: https://controlc.com/10370640">https://controlc.com/10370640



(Sorry ! Impossible to paste code here, because of "internal server error")
#3
Sorry, I could not indent the previous code, because it caused an "internal server error" (?!)
#4
So, maybe like this (probably improvable):

(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
#5
Oh my apologies! I reversed x and y (in `letex`) when transcribing... :/


(define (make-adder x)
  (letex (y x)
    (fn (z) (+ y z))))
   
(setq add2 (make-adder 2))
(println (add2 4))
; 6
#6
Maybe this way, but it's not quite the same:

(define (make-adder x)
  (letex (x y)
    (fn (z) (+ y z))))
   
(setq add2 (make-adder 2))
(println (add2 4))
> 6
#7
First, you need to understand how the function http://www.newlisp.org/downloads/newlisp_manual.html#import">import works. And see some examples where it is used, like http://www.newlisp.org/syntax.cgi?code/opengl-demo-ffi-lsp.txt">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 repetitive, to create a module that can be used by programs.
#8
newLISP in the real world / Re: using ref data
September 02, 2020, 03:14:14 AM
Quote from: cameyo post_id=24928 time=1599032047 user_id=732
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.
#9
newLISP in the real world / Re: using ref data
August 31, 2020, 06:38:25 AM
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 https://en.wikibooks.org/wiki/Introduction_to_newLISP/Lists#Find_and_replace_matching_elements">here (see 'find-all' at the end).
#10
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 macro 'f' to avoid variable capture in passed parameters
#11
Quote from: lyl post_id=24920 time=1598594057 user_id=1262
(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 :
(dolist (x a)
  (let (z $idx)
    (set (sym x) (expand (lambda (y) z) 'z))))
#12
Quote from: cameyo post_id=24891 time=1593772007 user_id=732
thank you. I learned new things.

You're welcome! I learned new things too... :)
#13
In this case we could also do:
> (apply + (map (fn (x) (int (if (starts-with x "0") (rest x) x))) (find-all {[0-9]+} "o123p010iru5")))
138
#14
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 salad and salad)

or (define (rember-f test? a l) (cond and so on ...))
#15
Yes, map is a very useful function which works well in parallel.

It is handy too to take the place of 'list comprehensions'...