Embedded Quotes Revisted

Dar Scott dsc at swcp.com
Mon May 17 17:13:38 EDT 2004


On Monday, May 17, 2004, at 01:27 PM, Judy Perry wrote:

> ========================================
> answer "She said, " & q("I do.")
>
> function q what
>   return quote & what & quote
> end q
> =======================================
>
> Is there anyone who can translate this from geekSpeak to 
> normalHumanSpeak?
> (sorry; I'm no programmer)

Since I am a geek this is hard for me to do and I might fail, but my 
comments might help a little.

It is possible to build a custom function as well as a custom command.  
Unlike a custom command a custom function can be used in an expression. 
  This is because it generates or returns a value.

Consider this in a button script:

on mouseUp
    put next(5)
end mouseUp

function next x  -- returns the number after x
   return x+1
end next

This will put 6 into the message box.

Just as the definition of the custom command "mouseUp" starts with 
'on', the definition of the custom function "next" starts with 
'function'.

Just as the custom command "mouseUp" has a name, the function has a 
name.  The function name is "next".

It takes one parameter; it is named x.

It returns a value.  The return command takes an expression.  In this 
case it is x+1.

When next() is called it is passed the value 5, which becomes the value 
for x.  This is added to 1 and returned.  Thus the command in the 
mouseUp handler gets the value 6.

This can be applied to the quoting function.

In the example, q() is called with the value "I do." which becomes the 
value of the parameter named 'what'.

The value of 'what':
I do.

The constant 'quote' is equivalent to a string containing a single 
double quote character.

The value of the expression in the return command is this:
"I do."

Thus the answer command is equivalent to this:
answer "She said, " & quote & "I do." & quote

The line in the answer dialog box is this:
She said, "I do."

Since I am a geek, I am probably leaving out some crucial component for 
understanding this.  I may have paid the cost to learn that component 
long ago and have forgotten what it takes to understand that.

Dar Scott



More information about the use-livecode mailing list