Alternative to PUT value INTO variable

Something you want to see in a LiveCode product? Want a new forum set up for a specific topic? Talk about it here.

Moderators: Klaus, FourthWorld, heatherlaine, robinmiller, kevinmiller

RickA1
Posts: 13
Joined: Fri Mar 07, 2014 12:31 pm
Location: Brazil

Alternative to PUT value INTO variable

Post by RickA1 » Fri Mar 28, 2014 3:11 am

I would like to be able to write it in a fast way with multiple comma separated evaluations in the algebraic order (x=value, instead of put value into x)

Another semantic for the SET keyword enabling it to handle this could be an option like:

SET theVar = theValue, theVar1 = theValue1, ... theVarN = theValueN

Much like the LOCAL keyword does but just setting the new value of an already created local or global variable.

For properties nothing changes.

SET the property TO value -- Still use TO for properties

------ What's the difference? ----

Code: Select all

# Old Syntax
PUT 54.3 INTO X
PUT X * 17 INTO Y
PUT Y / 4 INTO Z

# Proposed alternative syntax/semantics

SET X = 54.3, Y = X * 17, Z = Y / 4

# Commas starts new attributions, and at end of a line, triggers continuation on the next line,
# and you can do this if you wish:

SET X = 54.3,
    Y = X * 17,
    Z = Y / 4

--Less verbose, a bit more clear to follow the sequence.
Last edited by RickA1 on Fri Mar 28, 2014 3:52 pm, edited 1 time in total.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 2788
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria
Contact:

Re: Alternative to PUT value INTO variable

Post by richmond62 » Fri Mar 28, 2014 11:20 am

I don't see any particular advantage with what you propose.

RickA1
Posts: 13
Joined: Fri Mar 07, 2014 12:31 pm
Location: Brazil

Re: Alternative to PUT value INTO variable

Post by RickA1 » Fri Mar 28, 2014 12:20 pm

The advantage is listed. Write fast, write less, be more clear.

Code: Select all

# Wordy salad

PUT 54.3 INTO X
PUT X * 17 INTO Y
PUT Y / 4 INTO Z

# Setting X, Y and Z, more comfortable to read in a glance. More Math friendly.
# Ease to write in less keystrokes. Syntax closer to 99% of other current languages
# As an alternative, it does not break current code

SET X = 54.3,
    Y = X * 17,
    Z = Y / 4


richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 2788
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria
Contact:

Re: Alternative to PUT value INTO variable

Post by richmond62 » Sat Mar 29, 2014 8:36 pm

At which point the language starts looking less like xTalk and more like something else.

"Syntax closer to 99% of other current languages"

that certainly doesn't impress me: in fact that is one of the reasons I use Livecode INSTEAD of any othe language.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5616
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Alternative to PUT value INTO variable

Post by dunbarx » Sun Mar 30, 2014 6:06 am

"x = 42". Of course this would be interpreted by the parser as a statement that is evaluated either "true" or "false".

Set x = 42. Well, this could probably be implemented without crashing the whole edifice.

The "put into" construction and its cousins were designed explicitly by Dan Winkler and Bill Atkinson to be palatable to non programmers, "the rest of us, in 1987 parlance, though those two could scarcely be categorized that way. The idea proposed is to use the "set" command without the word "the" to parse subsequent tokens as a new command instead of setting a property. Too close to what we are used to. I would vote no.

Could another construction work? Is it desirable? Like Richmond, I see little gain in compactness.

Craig Newman

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6215
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Alternative to PUT value INTO variable

Post by FourthWorld » Sun Mar 30, 2014 7:35 am

dunbarx wrote:Too close to what we are used to. I would vote no.
I'm inclined to like the idea for that exact same reason.
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

SparkOut
Posts: 1822
Joined: Sun Sep 23, 2007 4:58 pm

Re: Alternative to PUT value INTO variable

Post by SparkOut » Sun Mar 30, 2014 9:00 am

I wouldn't mind "set tVar1 to 50,tVar2 to 100" but a definite no from me for the use of = in the structure.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5616
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Alternative to PUT value INTO variable

Post by dunbarx » Sun Mar 30, 2014 4:52 pm

Hmmm.

Rereading, and thinking about what Richard felt, maybe "set" could have this entirely new meaning. It would not be the first time a native word was used in more than one way. English speakers are used to that, after al.

I am so accustomed to having a list of preset values where I can quickly find what I am looking for:

put 1 into x
put 2 into y
put 3 into z
...

that I dismissed the linear version out of hand:

set x to 1,y to 2,z to 3...

It would be harder to find a particular value in a long string, but so what, as long as the original option still lived. That is a matter of personal style.

Craig

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2695
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: Alternative to PUT value INTO variable

Post by mwieder » Sun Mar 30, 2014 4:56 pm

The problem with "=" is that the engine's parser is already configured to interpret that as a comparison rather than an assignment.
That said, it's not the difficult to handle this with a preprocessor: convert "x=y" to "put y into x", "==" to "is". I did this in a preprocessor for a while, but later dropped it because a) nobody was interested and b) I got bored playing with it and the only advantage it offered was in translating code from other languages.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6215
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Alternative to PUT value INTO variable

Post by FourthWorld » Sun Mar 30, 2014 7:17 pm

Anything but "==", among the dumbest decisions any language designers ever made.

Why can't the parser be context-aware enough to know when=is a comparison and when it's an assignment?

Are there any contexts in which both would be acceptable? I can't think of any, and last time we ran this by this list I don't believe anyone else came up with any either, did they?
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2695
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: Alternative to PUT value INTO variable

Post by mwieder » Sun Mar 30, 2014 7:43 pm

Yes, in C/C++ it's a standard cutesy way of combining both an assignment and a comparison. You'll usually get a warning from the compiler to ensure that that's what you really meant, but you can say things like

Code: Select all

if (x = someFunction(y)) then
...
which both assigns a value to x and checks the boolean result of the function.

Not that I'm recommending this practice, just that it happens, and is an argument as to why the "==" operator exists.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6215
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Alternative to PUT value INTO variable

Post by FourthWorld » Sun Mar 30, 2014 10:03 pm

Good example. Thankfully the OP's suggestion was for a statement beginning with"set", which would help us avoid that ambiguity here, no?
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2695
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: Alternative to PUT value INTO variable

Post by mwieder » Sun Mar 30, 2014 10:15 pm

It would. I've never been fond of the "set" verb, or the "let" verb for that matter, but it would solve that problem.
I think a more xtalky syntax, though, would be something like:

Code: Select all

set x to 3
set y to "hello", z to 3.14, myVar to someArray["whatEver"]

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 2788
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria
Contact:

Re: Alternative to PUT value INTO variable

Post by richmond62 » Sun Mar 30, 2014 10:24 pm

Mark's comment about C/C++ begs the question:

Are we to keep Livecode as "Hypercard for Grownups", or is it going to be transmogrified
into a sort of Visual C++?

If people want a type of Visual C++ then why don't they trot off and develop a C++, which might be a sort of C++ with the
WYSIWYG IDE of Livecode slapped on the front.

But Livecode as it is is "Hypercard ++" with all that entails, and all the historical 'baggage' that goes along with it.

There are quite a few Object Oriented and Object Based programming setups "out there" all ready, and a lot of ones
that have fallen by the wayside (think HyperNext) because they tried to be both things at the same time:

funky Hypercard-like GUI with a non-Hypercard-like progging language underneath the covers: effectively sending mixed
signals to confuse people.

If one views "put" like the "LET" statement in BASIC then it is unnecessary; and that is why in later versions of BASIC "LET" was optional;
but a "put" statement does not work like a "LET" statement, mainly because a "put" statement as well as allowing you to assign values to constants
and variables, allows you to PUT values and strings into FIELDS, to move values and strings between containers, and so on.

-------------------------------------------

It would be entirely doable to have these sorts of statements:

varXXX = 978 and stringZZZ = "with knobs on"

but when you want to start moving things around between containers you'll still need something like a "put" command.

stringHHH = stringGGG + stringJJJ could also turn out to be a right PIB as that sort of code does not wear its colours on
its chest and is difficult to sort out when it goes wrong.

RickA1
Posts: 13
Joined: Fri Mar 07, 2014 12:31 pm
Location: Brazil

Re: Alternative to PUT value INTO variable

Post by RickA1 » Mon Mar 31, 2014 3:54 pm

mwieder wrote:It would. I've never been fond of the "set" verb, or the "let" verb for that matter, but it would solve that problem.
I think a more xtalky syntax, though, would be something like:

Code: Select all

set x to 3
set y to "hello", z to 3.14, myVar to someArray["whatEver"]
You could write it more readable breaking the line like:

Code: Select all

set x to 3,
    y to "hello", -- this is great for remarks per line
    z to 3.14,
    myVar to someArray["whatEver"]

#And, using "=" as a synonym to "TO" in this context (my initial pledge), if possible, it would be great and likable to newcomers from other languages:

set x = 3,
    y = "hello", -- Here we put the "Hi people"
    z = 3.14,    -- Here we set Pi
    myVar = someArray["whatEver"]

# Remember, LOCAL does this for initialization. SET could do this to replace values. LOCAL should follow the continuation, after comma, in the next line too (currently it's not).
richmond62 wrote:still need something like a "put" command.
Richmond, you probably missed my statement:

# As an alternative syntax, nothing changes, it does not break current code

No one is proposing to remove PUT, just create an alternative shortcut syntax allowing people to choose.

Post Reply

Return to “Feature Requests”