Can a function return two values?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Re: Can a function return two values?
At a tangent, I was wondering where I could find an (old) article by (IIRC) Richard (Fourth World) concerning a technique to return a value from a function as well as specific value in "the result". I am at a loss to track it down.
Re: Can a function return two values?
Did you check his website?
http://www.fourthworld.com/rev/index.html
http://www.fourthworld.com/rev/index.html
Re: Can a function return two values?
Well, yes. But not successful in tracking it down. I am not even certain, but I think Richard was the author.
Re: Can a function return two values?
Did you check in the journal? If it isn't there, you might find it in his revNet plugin...
or in the number of tutorials he had in a much older version of RR...
or possibly in this stack...
or my last guess, the scripting conferences?
-
- VIP Livecode Opensource Backer
- Posts: 9842
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: Can a function return two values?
That may have been an either/or, as in being able to return a value from a command with "the result". If I'd written that a function can do both I don't recall what it is. And if I did, since apparently it's not easy to remember I don't think I'd recommend it even if I knew what it was.
An array seems simplest for the OP's use case.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
-
- VIP Livecode Opensource Backer
- Posts: 9669
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Can a function return two values?
You may be referring to the ability of a command handler, as opposed to a function handler, to return a result.
The difference is that the control structure "return" puts a value into "the result" whereas in a function handler, return, er, returns a value.
Craig Newman
The difference is that the control structure "return" puts a value into "the result" whereas in a function handler, return, er, returns a value.
Code: Select all
on mouseUp
resultTest
answer the result
end mouseUp
on resultTest
repeat with y = 1 to 10
if y = 5 then return random(99)
end repeat
end resultTest
Last edited by dunbarx on Fri Feb 01, 2019 9:11 pm, edited 1 time in total.
-
- VIP Livecode Opensource Backer
- Posts: 7237
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Can a function return two values?
Me too, and also numtochar(8) as a secondary delimiter. No one can put those into text when typing.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- Livecode Opensource Backer
- Posts: 9388
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Can a function return two values?
I am a simple soul (well, let's pretend that is true for the moment) . . .
Imagine a sentence:
"I am a Scottish man who lives in Bulgaria"
and imagine I want to chop this up into 2 subsentences:
"I am a Scottish man" and
"who lives in Bulgaria"
I have a feeling that a function to do that sort of thing should be about 5 to 10 minutes work:
- -
Of course that is extremely basic and just looks for the word "who", but looking for a designated item delimiter
would be just as easy.
Imagine a sentence:
"I am a Scottish man who lives in Bulgaria"
and imagine I want to chop this up into 2 subsentences:
"I am a Scottish man" and
"who lives in Bulgaria"
I have a feeling that a function to do that sort of thing should be about 5 to 10 minutes work:
- -
Code: Select all
on mouseUp
put empty into fld "f1"
put empty into fld "f2"
put fld "ff" into FFFF
put "z" into XXX
repeat until FFFF is empty
if (word 1 of FFFF) is not "who" and XXX is not "x" then
put ((word 1 of FFFF) & " ") after fld "f1"
delete word 1 of FFFF
else
put "x" into XXX
put ((word 1 of FFFF) & " ") after fld "f2"
delete word 1 of FFFF
end if
end repeat
end mouseUp
would be just as easy.
- Attachments
-
- Splitter.livecode.zip
- Here's the stack.
- (1.14 KiB) Downloaded 119 times
-
- VIP Livecode Opensource Backer
- Posts: 7237
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Can a function return two values?
You're looking at writing a full syntax parser, which isn't an easy task. There are commercial programs that claim to do it but I'm not sure even those are perfect.
Google Docs tries to help with that if you turn on the option and it gets it wrong half the time.
Google Docs tries to help with that if you turn on the option and it gets it wrong half the time.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- VIP Livecode Opensource Backer
- Posts: 3581
- Joined: Mon Jan 22, 2007 7:36 am
- Location: Berkeley, CA, US
- Contact:
Re: Can a function return two values?
Well, leaving aside the fact that "who lives in Bulgaria" is a dependent clause rather than a subsentence (unless you want to stack a ? at the end, and then this becomes a different discussion)...
You might try breaking on a finite set of words that trigger a dependency, "who" being one of them.
But I think Jacque is right - trying to treat the English language as something logical is a fool's errand.
Jacque - if Google docs gets it right half the time, maybe you could just use half the results.
You might try breaking on a finite set of words that trigger a dependency, "who" being one of them.
But I think Jacque is right - trying to treat the English language as something logical is a fool's errand.
Jacque - if Google docs gets it right half the time, maybe you could just use half the results.
PowerDebug http://powerdebug.ahsoftware.net
PowerTools http://www.ahsoftware.net/PowerTools/PowerTools.irev
PowerTools http://www.ahsoftware.net/PowerTools/PowerTools.irev
-
- VIP Livecode Opensource Backer
- Posts: 7237
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Can a function return two values?
Heh. I wonder what it would do if I started writing like Yoda.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- VIP Livecode Opensource Backer
- Posts: 9669
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Can a function return two values?
Richmond.
I may be either oversimplifying or trivializing what you want to do, but with your sentence in a field 1:
You could use the itemDel similarly.
Craig
I may be either oversimplifying or trivializing what you want to do, but with your sentence in a field 1:
and knowing where the break is going to be, either at a word, the word number, whatever:I am a Scottish man who lives in Bulgaria
Code: Select all
on mouseUp
put fld 1 into tText
answer "Break where?" with "word" or "word number"
if it is "word number" then
ask "word number?"
answer word 1 to it - 1 of tText & return & word it to 100000 of tText
else if it is "word" then
ask "Word?"
put wordOffset(it,tText) into wordNum
answer word 1 to wordNum - 1 of tText & return & word wordNum to 100000 of tText
end if
end mouseUp
Craig
-
- Livecode Opensource Backer
- Posts: 9388
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Can a function return two values?
Indeed I could . . . but my 'problem' is that I spend an awful lot of time with children between 6 and 11 years oldYou could use the itemDel similarly.
so I tend to simplify things.
-
- Livecode Opensource Backer
- Posts: 9388
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Can a function return two values?
Ooh, sorry, I forgot to wear my Grammar-Queen frock today.Well, leaving aside the fact that "who lives in Bulgaria" is a dependent clause
-
- Livecode Opensource Backer
- Posts: 9388
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Can a function return two values?
About as likely as my waking up in bed one day and finding my wife has been replaced by a robot and I haven't noticed.a full syntax parser