defstruct Questions

However, the example I posted was a watered down version of what I am
doing and currently I need to access the list as it's being built to
look for repetitive entries. Is there a way to access the uncompleted
list while still inside the mapcar function?
I think not. But that's definitely not your problem, you can revert to your previous implementation,
it shouldn't change anything. Maybe just a restart of icfb solved you problem...


Stéphane
 
J

Jester_EE

Guest
I have a few questions with the use of defstruct in a SKILL program I
am currently working on.

1. I am currently globally defining the defstruct, but when I use the
make_<name> command in a procedure, it doe not know how to make the
structure. I found that if I redefine the defstruct in the procedure
it works, but I'd rather define it with the rest of the global data
structures I am using and not throughout my code. Any thoughts on
what I'm doing wrong?

ex.
defstruct(mystruct field1 field2 field3)

cv = geGetWindowCellView()
structList = myproc(cv)

procedure( myproc(cv)
let(x tlist
; defstruct(mystruct field1 field2 field3) ;This line needs to be
uncommented to work properly
tlist = nil
foreach(x cv~>instanceMasters
tlist = append1(tlist make_mystruct(
?field1 "Infoa"
?field2 "Infob"
?field3 "Infoc"
)
)
)
tlist
)
)

Will yield an: *Error* Name given not a defstruct - mystruct
2. When passing a list of defstructs to another procedure, it seems to
be losing it's association as a defstruct and becoming an array. I
know the data is stored as an array, but I no can longer reference the
elements by the defined structure fields. Thoughts?

ex.

myproc2(structList)

procedure( myproc2(listOfStructs)
let( (y)
foreach(y listOfStructs
someOtherProc(y->field1)
)
)
)

Will yield an: *Error* get/getq: first arg must be either symbol, list, defstruct or user type - array@0x14f99596
Any thoughts would be appreciated.

Thanks
Matt
 
I fixed my 2nd problem on my own. In the true code (not the example
above), I accidentally named my local 'listOfStructs' variable the
same as the defstruct type. The error was ambiguous and threw me off
track.

Still could use some help on the 1st problem though. I'm sick of the
CIW getting flooded with warnings of functions being redefined.

Thanks again!
Matt
 
procedure( myproc(cv)
let(x tlist
; defstruct(mystruct field1 field2 field3) ;This line needs to be
uncommented to work properly
tlist = nil
foreach(x cv~>instanceMasters
tlist = append1(tlist make_mystruct(
?field1 "Infoa"
?field2 "Infob"
?field3 "Infoc"
)
)
)
tlist
)
)
A comment : your syntax is wrong regarding the let() statement.

The first argument should be a *list* of the local variables, ie

let( (x tlist)

tlist = nil

...

) ; let

Note that the first statement (tlist=nil) is useless, since the variables are already initialized to
nil within the let(). Also, x doesn't need to be made local as this is done by the foreach
statement. Let me suggest a rewrite of this procedure :

procedure( myproc( cv )
foreach(mapcar x cv~>instanceMasters
make_mystruct(
?field1 "Infoa"
?field2 "Infob"
?field3 "Infoc"
) ; make_mystruct
) ; foreach
) ; procedure


Other than this, I see no problem. The defstruct doesn't need to be inserted in the procedure.


Cheers,

Stéphane
 
Stéphane,

Thank you for your feedback, I really appreciate it. The first error
(the let call) was a typo, but the mapcar implementation seemed to
work well and removed the error I was getting without the defstruct
being redefined each procedure call. Kinda strange that it worked
differently, but I won't complain.

However, the example I posted was a watered down version of what I am
doing and currently I need to access the list as it's being built to
look for repetitive entries. Is there a way to access the uncompleted
list while still inside the mapcar function?

Thanks again!
Matt
 

Welcome to EDABoard.com

Sponsor

Back
Top