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

#1
Thanks for all of those links, but I've read them already! :)



I'm aware that it's not CLISP or Scheme.  That's why I'm attracted to it.  I can't stand CLISP's bloat.



I was able to define an anaphoric if like this:


(define-macro (aif)
  (let ((it (eval (args 0))))
    (if it
      (eval (args 1))
      (eval (args 2)))))


And an example:


(aif (+ 23 42)
  (println it)
  (println "it's nil, bub."))


So it's a start.  I'm just exploring the idea of anaphora, and figured newLISP would be a good language to try it in.
#2
That's some nice code.



However, I'm failing when trying to use it to write another macro based on it:


(define-macro (alambda)
  (labels ((self (args 0) (1 args)))
    self))

(setf 'a (alambda (n) (if (= n 0) 1 (* n (self (- n 1))))))

(println (a 5))


I'm getting these errors:


ERR: symbol is protected in function let : self
called from user defined function labels
called from user defined function alambda


I'd like to be able to access "self" from a macro definition, so that I can define an anaphoric lambda macro to provide easy recursion.



:( My search continues.
#3
Hi all,



Wondering if there's an equivalent to flet or labels in newLISP.  I don't see any in the docs.  There might be a way to hack it together with letex and lambda, but I'm not sure.



Any help?



Thanks.
#4
Hello all,



I've been playing around with newLISP on my Raspberry Pi, and I whipped up a quick library to interface with the GPIO pins.



It's available here in case anyone's interested: https://github.com/gatesphere/raspi-gpio-newlisp">https://github.com/gatesphere/raspi-gpio-newlisp



Man this language is sexy.
#5
Thanks so much for this!  It makes a lot of sense.  And it seems to be correct, based on the following experiment:



newLISP v.10.4.4 on Linux IPv4/6 UTF-8, execute 'newlisp -h' for more info.

> (setf a '(inc 0 1))
(inc 0 1)
> a
(inc 0 1)
> (eval a)
1
> a
(inc 1 1)
> (eval a)
2
> a
(inc 2 1)
#6
Thanks cormullion.



I had found Kazimir's example prior to the (sum) example.  I understand Kazimir's function.



I'm having a hard time understanding either (sum) or the (changeme) that you introduced...



Is there any way you could walk me through what happens?



Thanks.



EDIT: Okay, I understand (changeme) now. It modifies the last element of the lambda by adding one to it each time it's called.  That's nice.



But how does (sum) do it's magic?  It doesn't look like there's anything to change... 0 is a number...
#7
Hello all...



So I came across this example function in the Code Patterns guide.  I'm new to newlisp, so this code is confusing me.  How does this function have memory?


(define (sum (x 0)) (inc 0 x))

I understand that (x 0) means that 0 is a default value for x, what I'm not understanding is why does sum rewrite itself?



I've traced it, and found that after a (sum 4), sum => (lambda ((x 0)) (inc 4 x))...  this confuses me.



Any help?  Thanks.