Sunday 15 February 2015

common lisp: slot-value for defstruct structures -


In common Lisp, what can I use to use the structure slot using slot name / symbol? (Slot-value, structure, slot) (slot-value, strat, slot)) (setf p (make) - (set (slot-value 'p' x) (1) ( Setf (-> P 'y) 2)

I am using Closer CL, and this work in Closer CL. However, AFAIK is a non-standard behavior (" Undefined behavior "equivalent to C ++.) I am planning to switch to any other CL implementation, so do I use the slot-value for the structures? Hey, or is there a better way to do this?

Typically you can use Excel's functions

Your code will be accessor function point-x and point-y . You can use those people. < P> You can also use SLOT-VALUE with the implementing structures which support it. I think most implementations (GCL will be an exception) Lisp Soft The software that believes that works for SLOT-VALUE structures I do not think the implementation will remove support for it. It is not in the standard, because some implementers do not want to give this functionality to deployed applications.

So the two ways are fine.

If you want a little name, go with the accessor:

  CL-USER 109 & gt; (Defrroll (point: conc-name) (x 0) (y 0)) POINT CL-USER 110 & gt; (Make Point: x 5: y3) #S (Issue: X5: Y3) CL-User 111 & gt; (Setf P1 *) #S (Issue: X5: Y3) Cl-User 112 & gt; (X P1) 5 CL-User 113 & gt; (Setf P2 (make-point: x 2: y3)) #S (Issue: X2: Y3) CL-User 114 & gt; (List P1P2) (# S (Issue: X5: Y3) #S (Issue: X2: Y3)) CL-User 115 & gt; (Mpc 'X' (list P1P2)) (5 ​​2)   

The package will be stopped by designating conflicts between different accessory functions.

If you want to write a short version of SLOT-VALUE , this is also OK. Write a macro or write an inlined function. Sure - why not?

As I said, SLOT-VALUE works with the structures in most implementations. In this case you do not imagine ANSI CL that it should not be taken care of. Implementation ANSI extends the CL space in many ways. For example, is working on SLOT-VALUE formations, CLOS is implementing streams in the form of classes, implementing conditions as CLOS classes, providing meta-object protocols Is ...,

No comments:

Post a Comment