Generic data stucture?

Pondering the philosophy behind the language
Locked
Cyril
Posts: 183
Joined: Tue Oct 30, 2007 6:27 pm
Location: Moscow, Russia
Contact:

Generic data stucture?

Post by Cyril »

Maybe I am reinventing the wheel, but this pattern seems useful for me:

Code: Select all

newLISP v.10.1.0 on Win32 IPv4, execute 'newlisp -h' for more info.

> (define (Struct:Struct) (apply context (cons (context) (args))))
(lambda () (apply context (cons (context) (args))))
> (new Struct 't)
t
> (map t '(year month day hour min sec micro doy dow tz dst) (now))
(2009 6 25 22 8 49 219840 176 5 2009269136 5251736)
> (setq t:year (+ t:year 1))
2010
> (t 'year (+ (t 'year) 1))
2011
A generic data structure which fields are accessible by both colon and functional notations. The later is useful for group assignment. And now I have a bunch of questions: do I reinvent the wheel? do I mislooked some caveats? can this be made simpler? does this seem useful after all?
With newLISP you can grow your lists from the right side!

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Post by cormullion »

Answers: Possibly. Possibly. Possibly. :) And Yes - I think that looks pretty useful! I'll try it out and see how it fits.

Locked