anonymous context-objects

For the Compleat Fan
Locked
BrickCaster
Posts: 18
Joined: Fri Jun 25, 2004 10:57 pm

anonymous context-objects

Post by BrickCaster »

i experiment with NewLISP and LEGO bricks, using the LDraw library standard.
i use a newlisp BRICK class, here is an excerpt:

Code: Select all

(constant 'red 4)

(context 'BRICK)

(define color MAIN:red)

(define (BRICK:new ctx col x y z)
  (MAIN:new BRICK ctx)
  (set 'ctx (eval ctx))
  (set 'ctx:color col)
  ctx
)
now what i want is to define LEGO models as a list of BRICKs:

Code: Select all

(list
  (BRICK:new 'ctx1 ...)
  (BRICK:new 'ctx2 ...)
  (BRICK:new 'ctx3 ...)
  (BRICK:new 'ctx4 ...)
  ...
)
the problem is i want anonymous context-objets, i don't want to name each brick in my LEGO models, some have 700+ bricks.

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

Sorry, there are no anonymous context objects in newLISP, but perhaps you can invent some numbering scheme i.e:

(BRICK:new (symbol (format "brick-%03d" 111)) 'blue) => brick-111

brick-111:color => blue

you could also do:

(map (fn(x) (BRICK:new (symbol (format "brick%03d" x)) 'blue)) (sequence 1 5))

=> (brick001 brick002 brick003 brick004 brick005)

For making several at once, etc.

Lutz

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

The you also could do:

Code: Select all

(set 'bricks (map (fn(x) (BRICK:new (symbol (format "brick%03d" x)) 'blue)) (sequence 1 5)))
 
 => (brick001 brick002 brick003 brick004 brick005)

(dolist (b bricks)
  (set 'b:color 'black))

brick003:color => black
you can refer to the bricks by variable, etc.

Lutx

BrickCaster
Posts: 18
Joined: Fri Jun 25, 2004 10:57 pm

Post by BrickCaster »

thanks for your help Lutz.

unfortunately, the more i experiment with NewLISP the more i discover how much i am biased towards the everything-is-a-first-class-value approach.

so i will probably convert my code to some Scheme or Scheme derivative.
that makes sense because animating LEGO scenes also requires some paralellism that can only be implemented using true continuations.

however, be sure i was really pleased to discover NewLISP and how well you maintain and support it.

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

good luck!

Lutz

nigelbrown
Posts: 429
Joined: Tue Nov 11, 2003 2:11 am
Location: Brisbane, Australia

Post by nigelbrown »

Regarding anon contexts perhaps a function that will return a random symbol name that is unique within a given (or current) context could be useful viz
(anon) -> gwei842y321rui1dygk1
(anon 'CTXZ) -> gwei842y321rui1dygk1
I've used the numbered symbol generation myself but sometimes
anything will do?

I'm sure a little function could be written for it but why keep inventing it - perhaps a topic for a 5c-tip?
Nigel

Locked