Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uwm.edu!wuarchive!brutus.cs.uiuc.edu!ux1.cso.uiuc.edu!midway!ellis.uchicago.edu!samr From: samr@ellis.uchicago.edu (Samuel A. Rebelsky) Newsgroups: comp.sys.mac.hypercard Subject: Re: passing param's by reference Message-ID: <1990Aug10.183431.6963@midway.uchicago.edu> Date: 10 Aug 90 18:34:31 GMT References: <83758@cc.utah.edu> Sender: news@midway.uchicago.edu (News Administrator) Organization: Univ. of Chicago Computer Science Dept. Lines: 117 In article <83758@cc.utah.edu> KOFOID@cc.utah.edu writes: >HyperTalk does not allow parameter passing by reference. If I understand >correctly, version 2 will be the same. This makes it difficult to write >generalized handlers for modular use. > If I understand your question(s) correctly, it is possible to create very general handlers by using the "do" command. For standard HyperCard objects (such as fields and buttons), you don't have to be too creative. For example, consider the following function that sets some text attributes of a more-or-less arbitrary object. -- HANDLER: -- setTextAttribs -- PARAMETERS: -- theObj -- a description of an object -- DESCRIPTION: -- Sets the attributes of the named object to my favorite values on setTextAttribs theObj do "set the textFont of" && theObj && "to Courier" do "set the textSize of" && theObj && "to 12" do "set the textStyle of" && theObj && "to bold,italic" end setTextAttribs In conjunction with handlers like the above, I often add a utility function called "quoteIt" that replaces single quotes with double quotes (you'll see why in a minute). -- FUNCTION: -- quoteIt -- PARAMETERS: -- theString -- a string -- DESCRIPTION: -- Returns a copy of theString with all instances of the single quote -- character (') replaced by a double quote ("). function quoteIt theString repeat while "'" is in theString put quote into char offset("'", theString) of theString end repeat return theString end quoteIt Now, calls to setTextAttribs can take many forms -- the only restriction is that you should pass a string that names the object. Some standard examples follow. -- use quoteIt to form the name of the object setTextAttribs quoteIt("card button 'Order Pizza'") -- use HyperTalk's "name of" function setTextAttribs (the name of card field "Favorite Toppings") -- put in the quotes by hand setTextAttribs "background field" && quote & "Cheeses Used" & quote -- abuse HyperTalk's willingness to "fill in the quotes" for objects -- whose name consists of a single word. setTextAttribs "background button Cook" Note that the four tricks above all work with many of the Dartmouth XCMDs/XFCNs (which suggest the latter two sol'ns). --- I'm not sure if the above completely answers your question, as it sounds like you actually want to reference variables rather than objects. As long as you deal with global variables, you should be able to use a similar technique. For example: -- HANDLER: -- doSquare -- PARAMETERS: -- theVar -- a text string containing the name of a numerica global -- variable -- DESCRIPTION: -- Squares the global variable "in place" on doSquare theVar global A,B,C,X,Y,Z -- include any global variables you may want square do "put" && theVar && "*" && theVar && "into" && theVar end doSquare -- HANDLER: -- testSquare -- PARAMETERS: -- none -- DESCRIPTION: -- Tests the "doSquare" routine on testSquare global X repeat forever ask "What initial value do you want to use" with 5 if it is empty then exit testSquare end if put it into X answer "X is originally" && X doSquare "X" answer "After one square operation, X is" && X doSquare "X" answer "After two square operations, X is" && X answer "Try it again?" with "Yes" or "No" if it is "No" then exit repeat end if end repeat end testSquare --- Clearly, this isn't all the elegant, and it's slower than one would hope (the "do" command takes a lot of extra time), but I hope that it at least gives you a start on what you want to do. I will warn you that excessive use of the "do" command makes debugging extremely painful. Samuel A. Rebelsky samr@cs.uchicago.edu or samr@midway.uchicago.edu