Page 2 of 3

Re: Can a function return two values?

Posted: Thu Jan 31, 2019 9:12 pm
by SparkOut
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?

Posted: Thu Jan 31, 2019 9:15 pm
by Klaus

Re: Can a function return two values?

Posted: Thu Jan 31, 2019 9:27 pm
by SparkOut
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?

Posted: Thu Jan 31, 2019 9:45 pm
by bogs
Did you check in the journal? If it isn't there, you might find it in his revNet plugin...
GoRev(Livecode)Net plugin...
GoRev(Livecode)Net plugin...
or in the number of tutorials he had in a much older version of RR...
Transcript WWWWhhhhaaa....?
Transcript WWWWhhhhaaa....?
or possibly in this stack...
Meta-fan-tabulous!
Meta-fan-tabulous!
or my last guess, the scripting conferences?

Re: Can a function return two values?

Posted: Thu Jan 31, 2019 10:46 pm
by FourthWorld
SparkOut wrote: Thu Jan 31, 2019 9:12 pm 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.
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.

Re: Can a function return two values?

Posted: Thu Jan 31, 2019 11:19 pm
by dunbarx
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.

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
Craig Newman

Re: Can a function return two values?

Posted: Fri Feb 01, 2019 6:32 pm
by jacque
mwieder wrote: Thu Jan 31, 2019 5:05 pm I regularly use numtochar(3) as a delimiter when I need something that is guaranteed to be unprintable.
Me too, and also numtochar(8) as a secondary delimiter. No one can put those into text when typing.

Re: Can a function return two values?

Posted: Wed Jun 30, 2021 9:50 am
by richmond62
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:
-
SShot 2021-06-30 at 11.47.56.png
-

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
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.

Re: Can a function return two values?

Posted: Wed Jun 30, 2021 5:52 pm
by jacque
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.

Re: Can a function return two values?

Posted: Wed Jun 30, 2021 6:13 pm
by mwieder
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. :P

Re: Can a function return two values?

Posted: Wed Jun 30, 2021 7:35 pm
by jacque
mwieder wrote: Wed Jun 30, 2021 6:13 pm Jacque - if Google docs gets it right half the time, maybe you could just use half the results. :P
Heh. :) I wonder what it would do if I started writing like Yoda.

Re: Can a function return two values?

Posted: Wed Jun 30, 2021 7:43 pm
by dunbarx
Richmond.

I may be either oversimplifying or trivializing what you want to do, but with your sentence in a field 1:
I am a Scottish man who lives in Bulgaria
and knowing where the break is going to be, either at a word, the word number, whatever:

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
You could use the itemDel similarly.

Craig

Re: Can a function return two values?

Posted: Wed Jun 30, 2021 7:48 pm
by richmond62
You could use the itemDel similarly.
Indeed I could . . . but my 'problem' is that I spend an awful lot of time with children between 6 and 11 years old
so I tend to simplify things. 8)

Re: Can a function return two values?

Posted: Wed Jun 30, 2021 7:49 pm
by richmond62
Well, leaving aside the fact that "who lives in Bulgaria" is a dependent clause
Ooh, sorry, I forgot to wear my Grammar-Queen frock today.

Re: Can a function return two values?

Posted: Wed Jun 30, 2021 7:50 pm
by richmond62
a full syntax parser
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. 8)