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

#436
newLISP newS /
December 03, 2007, 03:13:35 PM
Quote from: "cormullion"Sounds like a good idea - for all types to be equal!


You can sort a list that contains mixed-type elements, so I see no reason why you couldn't do the same for an array.  I wrote a C vector implementation a while ago that let you do this, you can use it just like a list, except insertions/removal from anywhere other than the back take longer.   You just have an array of pointers to "DataHolder" unions that can be anything.  It would then follow the same rules that sort uses for lists.
#437
newLISP newS /
December 03, 2007, 01:14:32 PM
Hi, I'm a newLISP newBIE and while trying to understand Lutz's awesome macro I went through and formatted it nicely in C-style and added comments.  If there are any other newbies out there that are confused by it perhaps this may help:


(define-macro (data-type)
(let (ctx (context (args 0 0)))
; sets the constructor
    (set (default ctx) (lambda () (args)))
; create getters and setters
    (dolist (item (rest (args 0)))

(set (sym item ctx) ; creates something like point:x

; the reason expand is used is because we want the
; point:x method to print stuff based on a number,
; not the value of a variable $idx when it's called.
; In other words it's the difference between:
; (print (my-list $idx))
; and
; (print (my-list 5))

(expand '(lambda-macro (_str _val)
(if (set '_val (eval _val))
; if value is specified act as a setter
          (nth-set ((eval _str) $idx) _val)
; otherwise act as a getter
          ((eval _str) $idx)
)
)
; internal var representing current index
; for dolist expression
'$idx
)
)
)
ctx
)
)
#438
newLISP newS / Better array support?
December 02, 2007, 06:44:18 PM
Is this planned for the future?  It would be nice if more of the functions that operated on lists would also operate on arrays, for example (sort).  As a big fan of newLISP I would be glad to help implement this myself, it's just that school won't give me a minute's rest.  :