Re: Passing parameters by reference

2012-03-13 Thread Dar Scott

On Mar 12, 2012, at 11:18 PM, Mark Wieder wrote:
 You'd have to somehow prevent the dereferencing of myArray[myKey] in
 order to pass it by reference.

Just as the dereferencing of x would have be be prevented to pass it as 
reference.  

Perhaps any mutable place is the same.

Dar
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Passing parameters by reference

2012-03-13 Thread Bob Sneidar
That is what passing an element to an array amounts to was my point. 

Bob


On Mar 12, 2012, at 5:39 PM, Pete wrote:

 I'm not sure whose post you're responding to Bob.  Where do you see
 something that amounts to a statement being passed as a referenced
 parameter?
 Pete
 
 On Mon, Mar 12, 2012 at 3:04 PM, Bob Sneidar b...@twft.com wrote:
 
 Just weighing in here, that would be a bit confusing. Passing by reference
 means that the command or function has access to the variable passed to it.
 By passing what amounts to a statement, there is nothing for LC to
 manipulate on the other end. Statements have to have some place to put the
 results. In this case, there is no place for LC to put the statement when
 passed by reference.
 
 Even a reference to an element of an array is a statement of sorts. That
 the command is in essence the characters for key delimiters [] doesn't
 change that. The array that is an element in a multidimensional array is
 not itself a container. The array is the container. To work with it you
 have to put it into it's own container then pass the new array by reference.
 
 I hope that makes sense. At least it does to me. :-)
 
 Bob
 
 
 On Mar 10, 2012, at 11:53 AM, Dar Scott wrote:
 
 Thanks for the tip, Dick, on using the list of keys.  One can think of
 arrays as nested or multidimensional.
 
 On Mar 10, 2012, at 1:06 AM, Dick Kriesel wrote:
 I agree it'd be good if LC could accept any array reference for
 invoking a handler that specifies pass-by-reference.
 
 Though is is probably more work, one might also consider chunks in
 pass-by-reference.
 
 Maybe any thing the subtract command can take.
 
 However, this might be a problem:
 
 doSomethingToTheseTwo char 1 to 2 of it, char 2 to 3 of it
 
 command doSomethingToTheseTwo @a, @b
  put butter into a
  put cheese into b
  put empty into a
 end doSomethingToTheseTwo
 
 That might also have a problem with this call:
 
 doSomethingToTheseTwo x, x[t]
 
 I immagine LiveCode folks can come up with a semantics that makes sense
 for weird cases.
 
 The subtract command does not have the the problem because it modifies
 only one thing.
 
 Dar
 
 
 ___
 use-livecode mailing list
 use-livecode@lists.runrev.com
 Please visit this url to subscribe, unsubscribe and manage your
 subscription preferences:
 http://lists.runrev.com/mailman/listinfo/use-livecode
 
 
 ___
 use-livecode mailing list
 use-livecode@lists.runrev.com
 Please visit this url to subscribe, unsubscribe and manage your
 subscription preferences:
 http://lists.runrev.com/mailman/listinfo/use-livecode
 
 
 
 
 -- 
 Pete
 Molly's Revenge http://www.mollysrevenge.com
 ___
 use-livecode mailing list
 use-livecode@lists.runrev.com
 Please visit this url to subscribe, unsubscribe and manage your subscription 
 preferences:
 http://lists.runrev.com/mailman/listinfo/use-livecode


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Passing parameters by reference

2012-03-13 Thread Dar Scott
Hi, Bob!

On Mar 13, 2012, at 9:37 AM, Bob Sneidar wrote:
 That is what passing an element to an array amounts to was my point. I think 
 what you are calling a statement many will call an expression.  

This concern is understandable.  However, I think we can distinguish between an 
expression that means a value and an expression that means a mutable place.  We 
have this distinction in LiveCode.

The expression '4 + a' can be used only as a value.  The expression a[3] can be 
used as a value or a mutable place.  That value is what is contained in that 
mutable place.  That mutable place is called a container in HyperCard.

We can't say 'put 7 into 4+a' but we can say 'put 7 into a[3]'.

The concept has strong HyperCard and LiveCode precedence.  We can say 'put 3 
into char 2 of item 6 of a'.  A chunk is a container.

Allowing @ parameters to refer to containers and not just variables can create 
some implementation challenges, perhaps, even some documentation challenges, 
but it does open the door to commands that can be used to, say, capitalize the 
value of containers.  I would hope the conceptual challenges in use would only 
apply to advanced users doing weird things.  

In the simplest case, the extension would replace variable with container 
in the description of @.  

I come from a background in functional programming in which just about 
everything is a value and not a container, but I have embraced the language 
used in LiveCode and the ability to modify things in ways besides replacing 
variable values and replacing properties.  

Dar
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Passing parameters by reference

2012-03-12 Thread Pete
Hi Dick,
Thanks again for this tip.  I ended up using it to solve my problem by
passing the whole array variable along with an optional second parameter
which is a list of comma-separated key values.  The function turns the key
values list into an array then uses it to access the data array.  If the
first parameter is a simple variable, then the second parameter isn't
present and the function can access it directly..

I'm wondering how you found about about this key values array feature?  I
can't find any mention of it in the dictionary or the reference manual and
it sure seems like something that should be known!

Thanks,
Pete

On Sat, Mar 10, 2012 at 12:06 AM, Dick Kriesel dick.krie...@mail.comwrote:

 LC has a way to get and set a node at any level of an array, without code
 that concatenates [ ] to specify the node.  In an array reference a single
 [ ] can enclose an array of keys,
 -- Dick


 script
 on mouseUp
   local tArray, tString
   put 4 into tArray[ 1 ][ 2 ][ 3 ]
   put getNodeViaListOfKeys( tArray, ( 1, 2, 3 )) after tString -- that is,
 get tArray[ 1 ][ 2 ][ 3 ]
   setNodeViaListOfKeys tArray, ( 5, 6, 7, 8 ), 9 -- that is, put 9 into
 tArray[ 5 ][ 6 ][ 7 ][ 8 ]
   put comma  getNodeViaListOfKeys( tArray, ( 5, 6, 7, 8 )) after tString
 -- 4,9
   breakpoint
 end mouseUp

 function getNodeViaListOfKeys @pArray, pList
   local tKeys
   put pList into tKeys
   split tKeys by comma and null
   return getNodeViaArrayOfKeys( pArray, tKeys )
 end getNodeViaListOfKeys

 function getNodeViaArrayOfKeys @pArray, @pKeysArray
   return pArray[ pKeysArray ]
 end getNodeViaArrayOfKeys

 command setNodeViaListOfKeys @rArray, pList, pValue
   local tKeys
   put pList into tKeys
   split tKeys by comma and null
   setNodeViaArrayOfKeys rArray, tKeys, pValue
 end setNodeViaListOfKeys

 command setNodeViaArrayOfKeys @rArray, @pKeysArray, @pValue
   put pValue into rArray[ pKeysArray ]
 end setNodeViaArrayOfKeys
 /script

 ___
 use-livecode mailing list
 use-livecode@lists.runrev.com
 Please visit this url to subscribe, unsubscribe and manage your
 subscription preferences:
 http://lists.runrev.com/mailman/listinfo/use-livecode




-- 
Pete
Molly's Revenge http://www.mollysrevenge.com
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Passing parameters by reference

2012-03-12 Thread Mark Wieder
Pete-

Monday, March 12, 2012, 10:19:14 AM, you wrote:

 I'm wondering how you found about about this key values array feature?  I
 can't find any mention of it in the dictionary or the reference manual and
 it sure seems like something that should be known!

Dick is well known as the master of arrays. I've learned to just
accept his advice without questioning.

-- 
-Mark Wieder
 mwie...@ahsoftware.net


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Passing parameters by reference

2012-03-12 Thread Dick Kriesel
On Mar 12, 2012, at 10:19 AM, Pete wrote:

 I'm wondering how you found about about this key values array feature?  I
 can't find any mention of it in the dictionary or the reference manual and
 it sure seems like something that should be known!

I found it while looking through bug reports for arrays, in 
http://quality.runrev.com/show_bug.cgi?id=7166 dated 2008-11-28.  So, thanks 
be to Mark Waddingham and David Bovill for that.

For convenience, here's Mark's reply to David:

Thanks for the suggestion.

This is on the list to include for the next version. In that version with:
  put tValue into tArray[tKey]
(indeed anywhere you can currently do tArray[tKey])

The meaning of 'tKey' will be extended:
  1) If it is a string then it is as it is now
  2) If it is a numerically keyed array starting at 1, then it will mean:
   put tValue into tArray[tKey[1]][tKey[2]]...[tKey[n]]
 where n is the number of elements in tKey
  3) Otherwise it is an error.

This will allow you to construct an array containing the path to the key you
want to modify/fetch/delete dynamically.

I agree, the feature's worth adding into the dictionary and manual.

-- Dick
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Passing parameters by reference

2012-03-12 Thread Dick Kriesel
On Mar 12, 2012, at 11:12 AM, Mark Wieder wrote:

 Dick is well known as the master of arrays. I've learned to just
 accept his advice without questioning.

I didn't know that!

But, I make so many misteaks that I have to recomend that you resume 
questoining.

-- Dick
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Passing parameters by reference

2012-03-12 Thread Bob Sneidar
Just weighing in here, that would be a bit confusing. Passing by reference 
means that the command or function has access to the variable passed to it. By 
passing what amounts to a statement, there is nothing for LC to manipulate on 
the other end. Statements have to have some place to put the results. In this 
case, there is no place for LC to put the statement when passed by reference. 

Even a reference to an element of an array is a statement of sorts. That the 
command is in essence the characters for key delimiters [] doesn't change that. 
The array that is an element in a multidimensional array is not itself a 
container. The array is the container. To work with it you have to put it into 
it's own container then pass the new array by reference. 

I hope that makes sense. At least it does to me. :-) 

Bob


On Mar 10, 2012, at 11:53 AM, Dar Scott wrote:

 Thanks for the tip, Dick, on using the list of keys.  One can think of arrays 
 as nested or multidimensional.
 
 On Mar 10, 2012, at 1:06 AM, Dick Kriesel wrote:
 I agree it'd be good if LC could accept any array reference for invoking a 
 handler that specifies pass-by-reference.
 
 Though is is probably more work, one might also consider chunks in 
 pass-by-reference.
 
 Maybe any thing the subtract command can take.
 
 However, this might be a problem:
 
 doSomethingToTheseTwo char 1 to 2 of it, char 2 to 3 of it
 
 command doSomethingToTheseTwo @a, @b
   put butter into a
   put cheese into b
   put empty into a
 end doSomethingToTheseTwo
 
 That might also have a problem with this call:
 
 doSomethingToTheseTwo x, x[t]
 
 I immagine LiveCode folks can come up with a semantics that makes sense for 
 weird cases.  
 
 The subtract command does not have the the problem because it modifies only 
 one thing.
 
 Dar
 
 
 ___
 use-livecode mailing list
 use-livecode@lists.runrev.com
 Please visit this url to subscribe, unsubscribe and manage your subscription 
 preferences:
 http://lists.runrev.com/mailman/listinfo/use-livecode


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Passing parameters by reference

2012-03-12 Thread Pete
I'm not sure whose post you're responding to Bob.  Where do you see
something that amounts to a statement being passed as a referenced
parameter?
Pete

On Mon, Mar 12, 2012 at 3:04 PM, Bob Sneidar b...@twft.com wrote:

 Just weighing in here, that would be a bit confusing. Passing by reference
 means that the command or function has access to the variable passed to it.
 By passing what amounts to a statement, there is nothing for LC to
 manipulate on the other end. Statements have to have some place to put the
 results. In this case, there is no place for LC to put the statement when
 passed by reference.

 Even a reference to an element of an array is a statement of sorts. That
 the command is in essence the characters for key delimiters [] doesn't
 change that. The array that is an element in a multidimensional array is
 not itself a container. The array is the container. To work with it you
 have to put it into it's own container then pass the new array by reference.

 I hope that makes sense. At least it does to me. :-)

 Bob


 On Mar 10, 2012, at 11:53 AM, Dar Scott wrote:

  Thanks for the tip, Dick, on using the list of keys.  One can think of
 arrays as nested or multidimensional.
 
  On Mar 10, 2012, at 1:06 AM, Dick Kriesel wrote:
  I agree it'd be good if LC could accept any array reference for
 invoking a handler that specifies pass-by-reference.
 
  Though is is probably more work, one might also consider chunks in
 pass-by-reference.
 
  Maybe any thing the subtract command can take.
 
  However, this might be a problem:
 
  doSomethingToTheseTwo char 1 to 2 of it, char 2 to 3 of it
 
  command doSomethingToTheseTwo @a, @b
put butter into a
put cheese into b
put empty into a
  end doSomethingToTheseTwo
 
  That might also have a problem with this call:
 
  doSomethingToTheseTwo x, x[t]
 
  I immagine LiveCode folks can come up with a semantics that makes sense
 for weird cases.
 
  The subtract command does not have the the problem because it modifies
 only one thing.
 
  Dar
 
 
  ___
  use-livecode mailing list
  use-livecode@lists.runrev.com
  Please visit this url to subscribe, unsubscribe and manage your
 subscription preferences:
  http://lists.runrev.com/mailman/listinfo/use-livecode


 ___
 use-livecode mailing list
 use-livecode@lists.runrev.com
 Please visit this url to subscribe, unsubscribe and manage your
 subscription preferences:
 http://lists.runrev.com/mailman/listinfo/use-livecode




-- 
Pete
Molly's Revenge http://www.mollysrevenge.com
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Passing parameters by reference

2012-03-12 Thread Mark Wieder
Pete-

Monday, March 12, 2012, 5:39:16 PM, you wrote:

 I'm not sure whose post you're responding to Bob.  Where do you see
 something that amounts to a statement being passed as a referenced
 parameter?

Here's the problem: a parameter of the form array[key] is not a
pointer to the key element of the array but rather the value stored
in the array. So saying

myArray[myKey] = hello
doSomethingWith myArray[myKey]

gives a parameter of hello to

on doSomethingWith @arg

You'd have to somehow prevent the dereferencing of myArray[myKey] in
order to pass it by reference.

-- 
-Mark Wieder
 mwie...@ahsoftware.net


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Passing parameters by reference

2012-03-10 Thread Dick Kriesel
On Mar 9, 2012, at 5:05 PM, Dar Scott wrote:

 Maybe the array could be global (or passed as a parameter) and the subscript 
 passed. ... There might be problems I don't see right off, such as access to 
 the same array at two different levels at the same time. 


Hi, Dar.  LC has a way to get and set a node at any level of an array, without 
code that concatenates [ ] to specify the node.  In an array reference a single 
[ ] can enclose an array of keys, as you can see in the code below.  Put the 
following into a button and click it.  The code invokes the debugger so you can 
see the array and the result string on the variables tab.

I agree it'd be good if LC could accept any array reference for invoking a 
handler that specifies pass-by-reference.  Pete, I'd be glad to vote for your 
enhancement request.

-- Dick


script
on mouseUp
   local tArray, tString
   put 4 into tArray[ 1 ][ 2 ][ 3 ]
   put getNodeViaListOfKeys( tArray, ( 1, 2, 3 )) after tString -- that is, get 
tArray[ 1 ][ 2 ][ 3 ]
   setNodeViaListOfKeys tArray, ( 5, 6, 7, 8 ), 9 -- that is, put 9 into 
tArray[ 5 ][ 6 ][ 7 ][ 8 ]
   put comma  getNodeViaListOfKeys( tArray, ( 5, 6, 7, 8 )) after tString -- 
4,9
   breakpoint
end mouseUp

function getNodeViaListOfKeys @pArray, pList
   local tKeys
   put pList into tKeys
   split tKeys by comma and null
   return getNodeViaArrayOfKeys( pArray, tKeys )
end getNodeViaListOfKeys

function getNodeViaArrayOfKeys @pArray, @pKeysArray
   return pArray[ pKeysArray ]
end getNodeViaArrayOfKeys

command setNodeViaListOfKeys @rArray, pList, pValue
   local tKeys
   put pList into tKeys
   split tKeys by comma and null
   setNodeViaArrayOfKeys rArray, tKeys, pValue
end setNodeViaListOfKeys

command setNodeViaArrayOfKeys @rArray, @pKeysArray, @pValue
   put pValue into rArray[ pKeysArray ]
end setNodeViaArrayOfKeys
/script

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Passing parameters by reference

2012-03-10 Thread Pete
Dick:

Thanks for the script, another little nugget of knowledge added to my LC
store!

I have entered an enhancement request - it's # 10070

Dar:

The function in question is a general purpose one that gets called from
many places.  Sometimes I need to pass an array element and other times
just a simple variable so I'd rather not complicate things by passing in an
extra parameter that holds the array key if it is an array that's being
passed.  But that is a possible solution so thanks for the suggestion.

Bob:

Creating a temporary array works, of course, and that's what I'm doing for
now.  But it defeats the whole purpose of passing the parameter by
reference since now I have to put the temporary array back into the real
array after the call.  I may as well just change the function to return the
result of its code and pass the parameter by value instead of reference.

Pete

On Sat, Mar 10, 2012 at 12:06 AM, Dick Kriesel dick.krie...@mail.comwrote:

 Hi, Dar.  LC has a way to get and set a node at any level of an array,
 without code that concatenates [ ] to specify the node.  In an array
 reference a single [ ] can enclose an array of keys, as you can see in the
 code below.  Put the following into a button and click it.  The code
 invokes the debugger so you can see the array and the result string on the
 variables tab.

 I agree it'd be good if LC could accept any array reference for invoking a
 handler that specifies pass-by-reference.  Pete, I'd be glad to vote for
 your enhancement request.

 -- Dick




-- 
Pete
Molly's Revenge http://www.mollysrevenge.com
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Passing parameters by reference

2012-03-10 Thread Dar Scott

On Mar 10, 2012, at 11:21 AM, Pete wrote:
 I may as well just change the function to return the
 result of its code and pass the parameter by value instead of reference.

Hmm.  Like this?

put modified(a[s]) into a[s]

This might be the best for now.  

Dar

---
Dar Scott
dba 
Dar Scott Consulting
8637 Horacio Place NE
Albuquerque, NM 87111

Lab, home, office phone: +1 505 299 9497
For Skype and fax, please contact.
d...@swcp.com

Computer Programming and tinkering,
often making LiveCode libraries and
externals, sometimes writing associated
microcontroller firmware.  
---



___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Passing parameters by reference

2012-03-09 Thread Pete
I think I already know the answer to this so just confirming in case I'm
missing something

Let's say I have a handler with a parameter that is passed by reference, eg
command xyz @parm1.  If I try to pass an element of an array, eg xyz
theArray[2], I get a runtime error.  If, however, I pass the whole array,
eg xyz theArray, all seems to work fine.

That seems somewhat strange to me but apparently that's the way it is?



-- 
Pete
Molly's Revenge http://www.mollysrevenge.com
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Passing parameters by reference

2012-03-09 Thread Dar Scott
Oh, that would be cool!  

Maybe the array could be global (or passed as a parameter) and the subscript 
passed.

This works:

add 1 to a[x]

...  it seems like a reasonable thing to do.  There might be problems I don't 
see right off, such as access to the same array at two different levels at the 
same time.  

Dar

On Mar 9, 2012, at 4:30 PM, Pete wrote:

 I think I already know the answer to this so just confirming in case I'm
 missing something
 
 Let's say I have a handler with a parameter that is passed by reference, eg
 command xyz @parm1.  If I try to pass an element of an array, eg xyz
 theArray[2], I get a runtime error.  If, however, I pass the whole array,
 eg xyz theArray, all seems to work fine.
 
 That seems somewhat strange to me but apparently that's the way it is?
 
 
 
 -- 
 Pete
 Molly's Revenge http://www.mollysrevenge.com
 ___
 use-livecode mailing list
 use-livecode@lists.runrev.com
 Please visit this url to subscribe, unsubscribe and manage your subscription 
 preferences:
 http://lists.runrev.com/mailman/listinfo/use-livecode



___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Passing parameters by reference

2012-03-09 Thread Pete
I have an update on this.  If the parameter passed is simply the name of
the array with no key qualifications, all is fine.  LC only kicks up a fuss
when  you pass a qualified array like myArray[myKey].  Weird.
Pete

On Fri, Mar 9, 2012 at 5:05 PM, Dar Scott d...@swcp.com wrote:

 Oh, that would be cool!

 Maybe the array could be global (or passed as a parameter) and the
 subscript passed.

 This works:

 add 1 to a[x]

 ...  it seems like a reasonable thing to do.  There might be problems I
 don't see right off, such as access to the same array at two different
 levels at the same time.

 Dar

 On Mar 9, 2012, at 4:30 PM, Pete wrote:

  I think I already know the answer to this so just confirming in case I'm
  missing something
 
  Let's say I have a handler with a parameter that is passed by reference,
 eg
  command xyz @parm1.  If I try to pass an element of an array, eg xyz
  theArray[2], I get a runtime error.  If, however, I pass the whole
 array,
  eg xyz theArray, all seems to work fine.
 
  That seems somewhat strange to me but apparently that's the way it is?
 
 
 
  --
  Pete
  Molly's Revenge http://www.mollysrevenge.com
  ___
  use-livecode mailing list
  use-livecode@lists.runrev.com
  Please visit this url to subscribe, unsubscribe and manage your
 subscription preferences:
  http://lists.runrev.com/mailman/listinfo/use-livecode



 ___
 use-livecode mailing list
 use-livecode@lists.runrev.com
 Please visit this url to subscribe, unsubscribe and manage your
 subscription preferences:
 http://lists.runrev.com/mailman/listinfo/use-livecode




-- 
Pete
Molly's Revenge http://www.mollysrevenge.com
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Passing Parameters

2011-11-09 Thread Mark Schonewille
Pete,

Most programmes were not written for socket communication. Instead, they write 
to stdout, which can be read from using the read from process command. Writing 
to stdout is much easier than writing to a socket. However, if you are writing 
the app you want to communicate with yourself, then you might as well use 
sockets. IIRC writing to stdout doesn't work correctly in LiveCode, which 
leaves sockets as a good alternative.

--
Best regards,

Mark Schonewille

Economy-x-Talk Consulting and Software Engineering
Homepage: http://economy-x-talk.com
Twitter: http://twitter.com/xtalkprogrammer
KvK: 50277553

Become our partner in sales http://qery.us/16r Start selling Color Converter 
today. 20% commission!

On 9 nov 2011, at 08:38, Pete wrote:

 Very useful lesson.  I guess I'm still interested in the
 differences/pros/cons of using sockets versus open process/read from
 process/write to process LC commands (assuming both processes are LC).  Do
 those commands use sockets under the covers?
 Pete
 Molly's Revenge http://www.mollysrevenge.com
 
 


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Passing Parameters

2011-11-09 Thread Alex Tweedly


If you have an existing program that reads from stdin and writes to 
stdout - and you want to control / monitor it from another app - then 
it'd be natural to just use 'read from process'. Or if you have a 
program that you don't own / develop you might have to use 'read from 
process'.


In general, using sockets is much more flexible and (once you've got 
over the initial hurdle of building socket communications once or twice) 
very simple - start with the lesson Phil pointed to, look at Chatrev, etc.


'read from process' has many limitations - in particular you need to 
poll for input, using the 'read from process... in x msecs form. If 
you use sockets then you can have the programs operate asynchronously, 
and have a handler that is called when data is ready for you. Or you can 
communicate with multiple other apps. Or move one of the apps to another 
machine (with some care over security). Or  almost anything.


-- Alex.



On 09/11/2011 07:38, Pete wrote:

Very useful lesson.  I guess I'm still interested in the
differences/pros/cons of using sockets versus open process/read from
process/write to process LC commands (assuming both processes are LC).  Do
those commands use sockets under the covers?
Pete
Molly's Revengehttp://www.mollysrevenge.com




On Tue, Nov 8, 2011 at 9:27 PM, Phil Davis


There is a nice intro to LC sockets here:
http://lessons.runrev.com/s/**lessons/m/4071/l/12924-How-to-**
communicate-with-other-**applications-using-socketshttp://lessons.runrev.com/s/lessons/m/4071/l/12924-How-to-communicate-with-other-applications-using-sockets

For inter-app communication, both apps are client AND server.
Phil




___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode




___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Passing Parameters

2011-11-09 Thread Björnke von Gierke
Note that these days most OSes will put up a security warning when you start to 
accept sockets, which you will need to do for inter-process communication. On 
corporate windows environments, accepting sockets might be disabled altogether 
for user processes.

On 9 Nov 2011, at 12:17, Alex Tweedly wrote:

 
 If you have an existing program that reads from stdin and writes to stdout - 
 and you want to control / monitor it from another app - then it'd be natural 
 to just use 'read from process'. Or if you have a program that you don't own 
 / develop you might have to use 'read from process'.
 
 In general, using sockets is much more flexible and (once you've got over the 
 initial hurdle of building socket communications once or twice) very simple - 
 start with the lesson Phil pointed to, look at Chatrev, etc.
 
 'read from process' has many limitations - in particular you need to poll 
 for input, using the 'read from process... in x msecs form. If you use 
 sockets then you can have the programs operate asynchronously, and have a 
 handler that is called when data is ready for you. Or you can communicate 
 with multiple other apps. Or move one of the apps to another machine (with 
 some care over security). Or  almost anything.
 
 -- Alex.
 
 
 
 On 09/11/2011 07:38, Pete wrote:
 Very useful lesson.  I guess I'm still interested in the
 differences/pros/cons of using sockets versus open process/read from
 process/write to process LC commands (assuming both processes are LC).  Do
 those commands use sockets under the covers?
 Pete
 Molly's Revengehttp://www.mollysrevenge.com
 
 
 
 
 On Tue, Nov 8, 2011 at 9:27 PM, Phil Davis
 
 There is a nice intro to LC sockets here:
 http://lessons.runrev.com/s/**lessons/m/4071/l/12924-How-to-**
 communicate-with-other-**applications-using-socketshttp://lessons.runrev.com/s/lessons/m/4071/l/12924-How-to-communicate-with-other-applications-using-sockets
 
 For inter-app communication, both apps are client AND server.
 Phil
 
 
 
 ___
 use-livecode mailing list
 use-livecode@lists.runrev.com
 Please visit this url to subscribe, unsubscribe and manage your subscription 
 preferences:
 http://lists.runrev.com/mailman/listinfo/use-livecode
 
 
 
 ___
 use-livecode mailing list
 use-livecode@lists.runrev.com
 Please visit this url to subscribe, unsubscribe and manage your subscription 
 preferences:
 http://lists.runrev.com/mailman/listinfo/use-livecode


-- 
Watch live presentations every Saturday:
http://livecode.tv

Use an alternative Dictionary viewer:
http://bjoernke.com/bvgdocu/

Chat with other RunRev developers:
http://bjoernke.com/chatrev/


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Passing Parameters

2011-11-09 Thread Pete
Thanks for the explanations - stopped me from going down the wrong path.
Pete
Molly's Revenge http://www.mollysrevenge.com




On Wed, Nov 9, 2011 at 3:17 AM, Alex Tweedly a...@tweedly.net wrote:


 If you have an existing program that reads from stdin and writes to stdout
 - and you want to control / monitor it from another app - then it'd be
 natural to just use 'read from process'. Or if you have a program that you
 don't own / develop you might have to use 'read from process'.

 In general, using sockets is much more flexible and (once you've got over
 the initial hurdle of building socket communications once or twice) very
 simple - start with the lesson Phil pointed to, look at Chatrev, etc.

 'read from process' has many limitations - in particular you need to
 poll for input, using the 'read from process... in x msecs form. If you
 use sockets then you can have the programs operate asynchronously, and have
 a handler that is called when data is ready for you. Or you can communicate
 with multiple other apps. Or move one of the apps to another machine (with
 some care over security). Or  almost anything.

 -- Alex.




 On 09/11/2011 07:38, Pete wrote:

 Very useful lesson.  I guess I'm still interested in the
 differences/pros/cons of using sockets versus open process/read from
 process/write to process LC commands (assuming both processes are LC).  Do
 those commands use sockets under the covers?
 Pete
 Molly's Revengehttp://www.**mollysrevenge.comhttp://www.mollysrevenge.com
 





 On Tue, Nov 8, 2011 at 9:27 PM, Phil Davis


 There is a nice intro to LC sockets here:
 http://lessons.runrev.com/s/lessons/m/4071/l/12924-How-to-http://lessons.runrev.com/s/**lessons/m/4071/l/12924-How-to-**
 communicate-with-other-applications-using-socketshtt**
 p://lessons.runrev.com/s/**lessons/m/4071/l/12924-How-to-**
 communicate-with-other-**applications-using-socketshttp://lessons.runrev.com/s/lessons/m/4071/l/12924-How-to-communicate-with-other-applications-using-sockets
 


 For inter-app communication, both apps are client AND server.
 Phil



  __**_
 use-livecode mailing list
 use-livecode@lists.runrev.com
 Please visit this url to subscribe, unsubscribe and manage your
 subscription preferences:
 http://lists.runrev.com/**mailman/listinfo/use-livecodehttp://lists.runrev.com/mailman/listinfo/use-livecode



 __**_
 use-livecode mailing list
 use-livecode@lists.runrev.com
 Please visit this url to subscribe, unsubscribe and manage your
 subscription preferences:
 http://lists.runrev.com/**mailman/listinfo/use-livecodehttp://lists.runrev.com/mailman/listinfo/use-livecode


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Passing Parameters

2011-11-08 Thread Phil Davis

On 11/7/11 12:47 AM, Phil Davis wrote:
If you need to send a message from app1 to app2, and app2 is already running, 
you could use socket communication between them. Don't have time to pencil it 
out, but maybe someone else will. If not, I'll do it tomorrow.


Phil


There is a nice intro to LC sockets here:
http://lessons.runrev.com/s/lessons/m/4071/l/12924-How-to-communicate-with-other-applications-using-sockets

For inter-app communication, both apps are client AND server.
Phil




On 11/7/11 12:28 AM, Phil Davis wrote:

On Mac OS X, you can do it from the command line.

1) create a standalone app (named Untitled1 in this example) that has this 
stack script:


   on startup
dispatch $1 to me
quit
   end startup

   on incoming
beep
   end incoming


2) create a different stack with this BUTTON script:

   on mouseUp
answer file Pick the app:
if it = empty then exit to top

get shell (it  /Contents/MacOS/Untitled1 incoming)
put the result after msg
   end mouseUp


3) click the button. It should start the Untitled1 app and you should hear 
the beep. At least it works here.


I haven't tried this on Windows, but I bet something similar would work there.

Phil Davis




On 11/6/11 7:35 PM, Cal Horner wrote:
Is there any command that will allow me to pass a simple parameter to a 
compiled LC  program?

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:

http://lists.runrev.com/mailman/listinfo/use-livecode







--
Phil Davis

PDS Labs
Professional Software Development
http://pdslabs.net


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Passing Parameters

2011-11-07 Thread Mark Schonewille
Hi Cal,

You can start up a standalone from the commandline with

C:/path/to/standalone.exe param1 param2,...
~/applications/standalone.app param1 param2...

In your standalone you can retrieve the values in $1, $2,... anywhere in your 
scripts:

put $1 into fld 1
get item 2 of $2

If your standalone is already running, you can use sockets to communicate. 
Here's http://qery.us/1a2 an example of using sockets for telnet communication. 
Once you understand how sockets work, you can use them for inter-application 
communication.

On Mac OS X, you can also use AppleScript:

set myScript to answer \hi\
tell application Revolution to do script myScript

Of course, the script limits apply, but if you only want to set the value of a 
variable, this should be sufficient.

--
Best regards,

Mark Schonewille

Economy-x-Talk Consulting and Software Engineering
Homepage: http://economy-x-talk.com
Twitter: http://twitter.com/xtalkprogrammer
KvK: 50277553

Become our partner in sales http://qery.us/16r Start selling Color Converter 
today. 20% commission!

On 7 nov 2011, at 04:35, Cal Horner wrote:

 Is there any command that will allow me to pass a simple parameter to a 
 compiled LC  program?



___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Passing Parameters

2011-11-07 Thread Richard Gaskin

Phil Davis wrote:


On Mac OS X, you can do it from the command line.

1) create a standalone app (named Untitled1 in this example) that has this
stack script:

on startup
 dispatch $1 to me
 quit
end startup


As an example of how to use environment variables that's an excellent 
one, but for production work it may pay to be a little paranoid, taking 
the view that an API like a command line is a potential point of 
security exposure.


Rather than execute anything that comes in on the command line, we could 
instead parse it to ensure it meets a list of acceptable commands:


on startup
  switch word 1 of $1
  case ExampleCommand1
  case ExampleCommand2
  case ExampleCommand3
 dispatch $1 to me
  default
 put Invalid command:  word 1 of $1
  end switch
  quit
end startup

For the relatively low cost of double-checking the command in the string 
$1 we can limit the range of things that the app can be used for.


It's a little more work, but prevents using the full range of LiveCode 
to manipulate the app in unintended ways.


--
 Richard Gaskin
 Fourth World
 LiveCode training and consulting: http://www.fourthworld.com
 Webzine for LiveCode developers: http://www.LiveCodeJournal.com
 LiveCode Journal blog: http://LiveCodejournal.com/blog.irv

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Passing Parameters

2011-11-07 Thread Pete
I've never tried the open.read from/write process commands - would those be
another way to do this?

Back in the days when I worked on HP3000 computers, they had something
called message files.  They were basically files that any number of
processes could write to and one process could read from and as a record
was read, it was deleted from the file.  It was a great and very easy way
to implement client/server communications.

Pete
Molly's Revenge http://www.mollysrevenge.com




On Mon, Nov 7, 2011 at 3:41 AM, Mark Schonewille 
m.schonewi...@economy-x-talk.com wrote:

 Hi Cal,

 You can start up a standalone from the commandline with

 C:/path/to/standalone.exe param1 param2,...
 ~/applications/standalone.app param1 param2...

 In your standalone you can retrieve the values in $1, $2,... anywhere in
 your scripts:

 put $1 into fld 1
 get item 2 of $2

 If your standalone is already running, you can use sockets to communicate.
 Here's http://qery.us/1a2 an example of using sockets for telnet
 communication. Once you understand how sockets work, you can use them for
 inter-application communication.

 On Mac OS X, you can also use AppleScript:

 set myScript to answer \hi\
 tell application Revolution to do script myScript

 Of course, the script limits apply, but if you only want to set the value
 of a variable, this should be sufficient.

 --
 Best regards,

 Mark Schonewille

 Economy-x-Talk Consulting and Software Engineering
 Homepage: http://economy-x-talk.com
 Twitter: http://twitter.com/xtalkprogrammer
 KvK: 50277553

 Become our partner in sales http://qery.us/16r Start selling Color
 Converter today. 20% commission!

 On 7 nov 2011, at 04:35, Cal Horner wrote:

  Is there any command that will allow me to pass a simple parameter to a
 compiled LC  program?



 ___
 use-livecode mailing list
 use-livecode@lists.runrev.com
 Please visit this url to subscribe, unsubscribe and manage your
 subscription preferences:
 http://lists.runrev.com/mailman/listinfo/use-livecode


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Passing Parameters

2011-11-07 Thread Phil Davis

Yes!
My example was mostly built on a 'lab experiment' model.

Phil


On 11/7/11 7:52 AM, Richard Gaskin wrote:

Phil Davis wrote:


On Mac OS X, you can do it from the command line.

1) create a standalone app (named Untitled1 in this example) that has this
stack script:

on startup
 dispatch $1 to me
 quit
end startup


As an example of how to use environment variables that's an excellent one, but 
for production work it may pay to be a little paranoid, taking the view that 
an API like a command line is a potential point of security exposure.


Rather than execute anything that comes in on the command line, we could 
instead parse it to ensure it meets a list of acceptable commands:


on startup
  switch word 1 of $1
  case ExampleCommand1
  case ExampleCommand2
  case ExampleCommand3
 dispatch $1 to me
  default
 put Invalid command:  word 1 of $1
  end switch
  quit
end startup

For the relatively low cost of double-checking the command in the string $1 we 
can limit the range of things that the app can be used for.


It's a little more work, but prevents using the full range of LiveCode to 
manipulate the app in unintended ways.


--
 Richard Gaskin
 Fourth World
 LiveCode training and consulting: http://www.fourthworld.com
 Webzine for LiveCode developers: http://www.LiveCodeJournal.com
 LiveCode Journal blog: http://LiveCodejournal.com/blog.irv

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:

http://lists.runrev.com/mailman/listinfo/use-livecode



--
Phil Davis

PDS Labs
Professional Software Development
http://pdslabs.net


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Passing Parameters

2011-11-07 Thread Phil Davis

On 11/7/11 8:42 AM, Pete wrote:

I've never tried the open.read from/write process commands - would those be
another way to do this?


Yes. See 'open process for neither' in the docs - it accomplishes the same thing 
as 'launch'.




Back in the days when I worked on HP3000 computers, they had something
called message files.  They were basically files that any number of
processes could write to and one process could read from and as a record
was read, it was deleted from the file.  It was a great and very easy way
to implement client/server communications.

Pete
Molly's Revengehttp://www.mollysrevenge.com




On Mon, Nov 7, 2011 at 3:41 AM, Mark Schonewille
m.schonewi...@economy-x-talk.com  wrote:


Hi Cal,

You can start up a standalone from the commandline with

C:/path/to/standalone.exe param1 param2,...
~/applications/standalone.app param1 param2...

In your standalone you can retrieve the values in $1, $2,... anywhere in
your scripts:

put $1 into fld 1
get item 2 of $2

If your standalone is already running, you can use sockets to communicate.
Here's http://qery.us/1a2 an example of using sockets for telnet
communication. Once you understand how sockets work, you can use them for
inter-application communication.

On Mac OS X, you can also use AppleScript:

set myScript to answer \hi\
tell application Revolution to do script myScript

Of course, the script limits apply, but if you only want to set the value
of a variable, this should be sufficient.

--
Best regards,

Mark Schonewille

Economy-x-Talk Consulting and Software Engineering
Homepage: http://economy-x-talk.com
Twitter: http://twitter.com/xtalkprogrammer
KvK: 50277553

Become our partner in sales http://qery.us/16r Start selling Color
Converter today. 20% commission!

On 7 nov 2011, at 04:35, Cal Horner wrote:


Is there any command that will allow me to pass a simple parameter to a

compiled LC  program?



___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your
subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode



___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode



--
Phil Davis

PDS Labs
Professional Software Development
http://pdslabs.net


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Passing Parameters

2011-11-06 Thread Cal Horner
Is there any command that will allow me to pass a simple parameter to a 
compiled LC  program?
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Passing Parameters

2011-11-06 Thread dunbarx
Hi


Parameters are passed along with command or function calls. Check the 
dictionary. Read the entries on command and function.  Look up the params 
and paramCount. Note that there are two methods of passing parameters, by 
value and by reference. Check the user gude as well.



You must make a simple stack and experiment. The natural LC syntax is easy to 
learn and fun to use. And incredibly powerful. Write back if you need more...



Craig Newman




-Original Message-
From: Cal Horner calhor...@xtra.co.nz
To: use-livecode use-livecode@lists.runrev.com
Sent: Sun, Nov 6, 2011 5:37 pm
Subject: Passing Parameters


Is there any command that will allow me to pass a simple parameter to a 
compiled 
LC  program?
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

 
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode