Main Board > Wish List

Short-hand syntax for anonymous arrays or objects initialization

<< < (2/3) > >>

Mike King:
Yes -- you will have to wait till May, but in answer to your question the WITH option simply acts as a if a LOCAL directive was executed prior the start of the method, called or performed program.

The data is passed by value so its a one-way into the invoked logic.

As for methods, the variable can be the same name as a property or local variable and it simply temporarily overrides its value.
For a CALL if the variable was the same an ENTER variable, the ENTER setting would override -- same as if you had a LOCAL prior the ENTER.

We had considered requiring the developer to provide a list of which variables you could pass in to the code using the WITH option, but we figured since this is only a programmer option and not something a end-user could take advantage of the extra overhead made little sense.

James Zukowski:
I was reviewing things for another topic, and stumbled across this one, with this comment:


--- Quote from: Mike King on September 11, 2020, 09:25:54 AM ---To quickly create and load an array try:

dim Y$[*]
read data from "Mike,Was,Here",sep="," to Y${ALL}

--- End quote ---

I've tried doing this type of thing, but it doesn't seem to work. More specifically:

--- Quote ----}read record (1,key=k$)Rec$
-}dim Fld$[*]
-}read data from Rec$,sep=sep to Fld${all}
-}?dim(read num(Fld$))
 0
-}?Fld$[1]
0001
-}?Fld$[2]

-}?dim(read num(Fld$))
 2
-}
--- End quote ---

Is there something I'm missing? I've been looking for something like this for a while.

Thanks!

keith.mcbride:
It seems to work if you pre-dim the array size:

0100 DIM y$[15]
0200 READ DATA FROM "a,b,c",SEP="," TO y${ALL}
0300 PRINT y$[0],'LF',y$[1],'LF',y$[2]
-;run
a
b
c

RobL:
Pardon me jumping in..

Try loading the dynamic array like this:

--- Code: ---Rec$="ZZZ"+sep+"YYY"+sep+"XXX"+sep
!
dim Fld$[*]
for element$ from Rec$
Fld$[*]=element$
next
!
print sub(rec(cpl("iolist Fld${all}")),sep,",")

--- End code ---

Hope this helps!

Regards,

Rob Leighton

James Zukowski:
Keith/Rob:
I've used both methods to load arrays. I noticed that Mike had used a dynamic array to do the loading in his example, but when I tried it, I only get 1 entry. Just looking for clarification.
Thanks for the ideas.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version