Search found 16 matches

by nikus80
Fri Dec 08, 2006 1:21 pm
Forum: newLISP newS
Topic: alternative indexing in nth
Replies: 21
Views: 14679

yes.

yours:
> (get-index 6 '(a b (c d e) f a))
(0)

mine:

> (get-index 6 '(a b (c d e) f a))
(4)

I wanted get flat length to return 1 on atoms, so it's more like:
(define (get-flat-length lst)
(if (list? lst) (length (flat lst)) 1))
by nikus80
Thu Dec 07, 2006 6:33 pm
Forum: newLISP newS
Topic: alternative indexing in nth
Replies: 21
Views: 14679

True, but get-index doesn't work with duplicated items. Of course that didn't seem to be an issue, but that's why I went the hard way. I got it working now. (define (get-index ind lst (current 0)) (if (not (list? lst)) '() (let (len (get-flat-length (first lst))) (if (> ind (- len 1)) (get-index (- ...
by nikus80
Wed Dec 06, 2006 2:39 am
Forum: newLISP newS
Topic: alternative indexing in nth
Replies: 21
Views: 14679

Mmm, I think you CAN single index a list. If we make a function which given a flat index returns a list that can be used with nth-set, we can easily write a macro as (define-macro (nth-flat-set) (eval (append '(nth-set) (get-index (args 0) (eval (args 1))) (rest (args)))))).... the function we need ...
by nikus80
Sat Dec 02, 2006 3:00 pm
Forum: newLISP newS
Topic: comma in parameter lists
Replies: 2
Views: 3105

comma in parameter lists

I'm using newLISP v9.0 on win.
I read about comma in parameters lists but they don't seem to work, what I'm doing wrong?

(define (test2 , b c)
,)

(test2 1 2 3)
returns 1! the comma is bounded!. Why is that?
by nikus80
Sat Dec 02, 2006 2:41 pm
Forum: newLISP newS
Topic: mystery quoting
Replies: 26
Views: 24765

I see what you mean. (apply list '('a 'b 'c)) is equivalent to (list ''a ''b ''c) so, (apply qq '(a b c)) is equivalent to (qq 'a 'b 'c) the thing is, I can't get rid of the quotes! with list, I can. (apply list (list a b c)) is equivalent to (list a b c) (apply qq (list a b c)) is not equivalent to...
by nikus80
Fri Dec 01, 2006 9:50 pm
Forum: newLISP newS
Topic: mystery quoting
Replies: 26
Views: 24765

Fanda, that's cool! that's exactly what I was wanting to do with apply! for the rest, there is something I'm doing wrong? They don't work! (define (prit) (print "printed!")) (define (ret-nil) '()) (define-macro (my-or) (let (val (eval (args 0))) (if val val (apply my-or (rest (map eval (args))))))) ...
by nikus80
Fri Dec 01, 2006 8:22 pm
Forum: newLISP newS
Topic: mystery quoting
Replies: 26
Views: 24765

it doesnt seems to work. I need my-or to eval only the arguments needed. my-or as a function is not what I need. (define (prit) (print "printed!")) (define (ret-nil) '()) (define-macro (my-or) (let (val (eval (args 0))) (if val val (eval (apply my-or (rest (args))))))) That doesn't work, because of ...
by nikus80
Thu Nov 30, 2006 2:47 am
Forum: newLISP newS
Topic: mystery quoting
Replies: 26
Views: 24765

suppose newLisp had lexical scoping. Forget macros for a second. imagine there is a function mydolist that receives a quoted code, and very much behaves like dolist (set 'lst '(1 2 3)) (let (a 3) (mydolist '(e lst) '(+ a 3))) when mydolist calls eval on '(+ a 3), what is the value of a? 3, you say. ...
by nikus80
Wed Nov 29, 2006 3:15 am
Forum: newLISP newS
Topic: mystery quoting
Replies: 26
Views: 24765

No, what I meant to say is that newLisp-like macros are only useful with dynamic scope. They're useless with lexical scope since the code you receive often refers the current enviroment variables.
by nikus80
Tue Nov 28, 2006 7:57 pm
Forum: newLISP newS
Topic: mystery quoting
Replies: 26
Views: 24765

I didn't mean you can't map or apply macro. What I meant to say is that if you are going to map 'n' apply your macro everywhere, it probably wants to be a function, not a macro. if not, which would be a good example (I can't think of anything, but maybe I'm being too scheme/commonlispy edit: BTW, wh...
by nikus80
Tue Nov 28, 2006 4:39 pm
Forum: newLISP newS
Topic: mystery quoting
Replies: 26
Views: 24765

I'm not very sure of what you're doing but macros arent supposed to be applied or mapped.
A macro doesn't evaluate his arguments, that means that, in newLISP, any call of a macro (mac a b c d) behaves like (mac 'a 'b 'c 'd) if mac were a normal function instead of a macro.
by nikus80
Mon Nov 27, 2006 12:55 pm
Forum: newLISP newS
Topic: Help with logic
Replies: 7
Views: 5803

If anything, you could write a macro to replace that or. something like (define-macro (nor) (catch (dolist (thisarg (args)) (let (evalarg (eval thisarg)) (if (or (isEmptyList? evalarg) evalarg) (throw evalarg)))).... or like (define-macro (lor , evalarg) (catch (dolist (thisarg (args)) (set 'evalarg...
by nikus80
Wed Nov 22, 2006 3:39 pm
Forum: Anything else we might add?
Topic: Fun with MAP
Replies: 23
Views: 30483

Fun with builders!

maybe this should go on the wiki, but a negator could be useful too. given a function, it returns a function which applies not to the result. And for example there is no need to define (elem?) and (not-elem?). Also useful for mapping, filtering, etc. sketch: (define (negate fun) (letex (fun fun) (fn...
by nikus80
Wed Nov 22, 2006 1:16 am
Forum: newLISP newS
Topic: newbie question
Replies: 4
Views: 4370

I just thought (rand 0) returned 0. Actually (rand 1) always returns 0, so it could be argued it is the true base case. That code seems fine, but I wonder how good it is at shuffling. For example, when you insert a 2, it is much more likely that you'll end up with (1 2) than with (2 1), which kinda ...
by nikus80
Tue Nov 21, 2006 8:47 pm
Forum: newLISP newS
Topic: newbie question
Replies: 4
Views: 4370

wow, thanks for the quick response. But I think that (rand 0) should always return 0, and to restart the counter one should have to write (rand 'restart) or something like that, 'cause it could be useful, I think... Just an opinion (of course, I can always write my own rand...). Of course in this ca...
by nikus80
Tue Nov 21, 2006 6:06 pm
Forum: newLISP newS
Topic: newbie question
Replies: 4
Views: 4370

newbie question

hi, I'm a newbie to lisp in general, though I know a few things about scheme and common lisp (I've read SICP, OnLisp, Practical Common Lisp, and Scheme The Programming Language, though I've finished none). I still don't understand a few things about newLISP. But I've tried writing a few routines. No...