Logic behind put URL or PUT URL into a variable

Bringing the internet highway into your project? Building FTP, HTTP, email, chat or other client solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9802
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Logic behind put URL or PUT URL into a variable

Post by FourthWorld » Tue Dec 08, 2020 11:46 pm

SparkOut wrote:
Tue Dec 08, 2020 10:36 pm
Certainly not a command, anyway.
There's more to LiveCode than commands and functions. "URL" is one of several forms of keywords, syntactically similar to "field": it tells us the type of a container, and the token that follows it specifies which container of that type is being referred to.

It seems like there's nothing all that magical going on here, just an anomaly in the parser that doesn't handle "URL" as gracefully as other keywords.

Long-time users can invent mnemonic rules like "think of it as a function" to help us remember that it requires parens, but newcomers don't know about this exceptional rule so the question keeps coming up several times every year.

Might be nice to fix the parser. But given the other things on their plate, I don't expect to see that soon. So it's just another gotcha, of the sort most languages have here and there.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

PaulDaMacMan
Posts: 616
Joined: Wed Apr 24, 2013 4:53 pm
Contact:

Re: Logic behind put URL or PUT URL into a variable

Post by PaulDaMacMan » Mon Dec 14, 2020 2:10 am

FourthWorld wrote:
Tue Dec 08, 2020 6:03 pm
jacque wrote:
Tue Dec 08, 2020 5:24 pm
PaulDaMacMan wrote:
Tue Dec 08, 2020 12:59 am
I always think of URL operator as a container like a variable or a card field except that container is a file/resource somewhere (locally / internet), and in that context it makes sense to me,
I think that's correct. When the URL term was updated back in the MetaCard days, the new feature description said, "URLs are now containers."
Exactly. Where in the language do other containers required parentheses around the container identifier? The presence of the URL keyword should suffice to inform the interpreter sufficiently on its own.
Point taken. But URL is actually two things, a file/resource path AND Also the contents of that file/resource? Or perhaps the path is more comparable to a property of the container?

Anyway if you substitute Card Fld for URL in the version that DOES work:

Code: Select all

 put "http://path.com/" into tUrl
put cd fld tUrl into tThis
answer tThis
It still wouldn't work anyway!
Answer tThis
would yield a dialog with the contents of a Card Field named tUrl (if there was one), rather then "text" that's in the variable tUrl
FourthWorld wrote:
Tue Dec 08, 2020 11:46 pm
SparkOut wrote:
Tue Dec 08, 2020 10:36 pm
Certainly not a command, anyway.
There's more to LiveCode than commands and functions. "URL" is one of several forms of keywords, syntactically similar to "field": it tells us the type of a container, and the token that follows it specifies which container of that type is being referred to.

It seems like there's nothing all that magical going on here, just an anomaly in the parser that doesn't handle "URL" as gracefully as other keywords.

Long-time users can invent mnemonic rules like "think of it as a function" to help us remember that it requires parens, but newcomers don't know about this exceptional rule so the question keeps coming up several times every year.

Might be nice to fix the parser. But given the other things on their plate, I don't expect to see that soon. So it's just another gotcha, of the sort most languages have here and there.
I still think that the URL/file "container" being similar to Field is the right analogy. I think the problem here may be that the resource pointed to is NOT actually a file but more like an executeble (php script) that has to create the data on the fly first before it can return it's "contents", and so needs to first be evaluated (executed) first which the parentheses forces the LC script interpreter to do (?). It's like pointing to a contents of an empty field and expecting to retrieve text contents that have yet been put into that card field?

But whatever way one wants to think about it that keeps it straight in their head is OK.
Last edited by PaulDaMacMan on Mon Dec 14, 2020 2:19 am, edited 1 time in total.
My GitHub Repos: https://github.com/PaulMcClernan/
Related YouTube Videos: PlayList

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9802
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Logic behind put URL or PUT URL into a variable

Post by FourthWorld » Mon Dec 14, 2020 2:12 am

PaulDaMacMan wrote:
Mon Dec 14, 2020 2:10 am
I still think that the URL/file "container" being similar to Field is the right analogy.
Maybe. Are users required to put parentheses around field names?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

PaulDaMacMan
Posts: 616
Joined: Wed Apr 24, 2013 4:53 pm
Contact:

Re: Logic behind put URL or PUT URL into a variable

Post by PaulDaMacMan » Mon Dec 14, 2020 2:38 am

Updated my previous post, I was mixed up, the version that DOES work as URL does NOT work as a Card Fld, it's actually the reverse, which seems to support the idea of it being inconsistent to behavior of other containers.
Maybe. Are users required to put parentheses around field names?
No, but neither are quotation marks required to be put around field names (non-strict interpreter mode), unless you also have a variable of the same name in the same script (yeah, I know, never a good idea), in which case the parentheses would force/ensure that the interpreter evaluates the contents of that variable to get the fld name rather than use the literal name of that variable as the field name. Not saying that is an equivalent to what's going on here, but I vaguely recall other (non-numeric) times where I've used parentheses to force/ensure the contents are evaluated first before the rest of the line.
My GitHub Repos: https://github.com/PaulMcClernan/
Related YouTube Videos: PlayList

PaulDaMacMan
Posts: 616
Joined: Wed Apr 24, 2013 4:53 pm
Contact:

Re: Logic behind put URL or PUT URL into a variable

Post by PaulDaMacMan » Mon Dec 14, 2020 3:01 am

Perhaps a better analogy would be a template container, not an actual container until it is used?
My GitHub Repos: https://github.com/PaulMcClernan/
Related YouTube Videos: PlayList

LCMark
Livecode Staff Member
Livecode Staff Member
Posts: 1206
Joined: Thu Apr 11, 2013 11:27 am

Re: Logic behind put URL or PUT URL into a variable

Post by LCMark » Mon Dec 14, 2020 7:39 pm

I have a feeling that this entire thread might have stemmed from a server-generated error rather than anything else...

There is no real difference (that I can think of) between:

Code: Select all

put URL "..." into tURL
answer tURL
and

Code: Select all

put "..." into tURL
put URL tURL into tContent
answer tContent
If a webserver generates an error you invariably get an error page back which (in its simplest form) will just contain "<error-code> <error description>". Bearing in mind the answer dialog will set htmlText on its message field if it thinks it has been given HTML - that is probably why it *appeared* that an an error resulted in the var, rather than the content of the page (Webservers usually return the error code in some HTML!).

So - I suspect either the URL was typed wrongly in the first example when it was run - or some server-side setup meant the intended page was, in fact, inaccessible at that point.

In terms of parentheses and the URL keyword, then the URL keyword is an 'object chunk' keyword (like field, button etc.) and it behaves the same as all others of those.

Chunk keywords bind tightly to the factor to their right - where a factor is basically any expression which is not a binary operator (and so can't cause an ambiguous 'chain' of things). (Technically, chunk keywords are prefix unary operators with precedence just below all binary operators).

Examples:

Code: Select all

put URL "Foo" into tURL
    => fetches URL "Foo" and places the contents into tURL
    
put URL "Foo" & "Bar" into tURL
    (bracketing to reflect precedence) => put ( URL ("Foo") ) & "Bar" into tURL
    => fetches URL "Foo", concatenates "Bar" to what that returned and places the contents into tURL
  
put URL ("Foo" & "Bar") into tURL
    (bracketing to reflect precedence) => put URL ( "Foo" & "Bar") into tURL
    => fetches URL "FooBar" and places the contents into tURL
Basically, the rules of when to parenthesise what you are URLing should be the same as those which apply to all object/control chunks.

Note: Chunks which *must* have a target (e.g. word, line, char etc.) do *not* need what they are operating on to be parenthesised:

Code: Select all

put word 1 + 2 + 3 of tFoo into tBar -- this is fine
This is simply because the parser that there has to be an "of" (or "to" - for ranges) after the (first) index expression so there is a natural terminator for it, so it doesn't need to restrict to just allowing factors.

sphere
Posts: 1145
Joined: Sat Sep 27, 2014 10:32 am
Location: Earth, Except when i Jump

Re: Logic behind put URL or PUT URL into a variable

Post by sphere » Mon Dec 14, 2020 10:26 pm

LCMark wrote:
Mon Dec 14, 2020 7:39 pm
I have a feeling that this entire thread might have stemmed from a server-generated error rather than anything else...
I can't relay that to the first message in this thread.
LCMark wrote:
Mon Dec 14, 2020 7:39 pm
So - I suspect either the URL was typed wrongly in the first example when it was run - or some server-side setup meant the intended page was, in fact, inaccessible at that point.
It are php scripts used as middleware to access the database. 99.999% no typo, as i copy/paste the URL and filename.
Files are only in use for development.

And the rest that you wrote i did not fully understand, hahahahaha.(because i'm tired)

I tried it several time, first method gave error, second method with variable did work as did the parenthesis (damn what a word, we say "haakjes")

and thanks to chime in.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9802
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Logic behind put URL or PUT URL into a variable

Post by FourthWorld » Tue Dec 15, 2020 12:16 am

Thank you, Mark. Seems the parens aren't so mystifying after all.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

AxWald
Posts: 578
Joined: Thu Mar 06, 2014 2:57 pm

Re: Logic behind put URL or PUT URL into a variable

Post by AxWald » Tue Dec 15, 2020 11:31 am

Hi,

just tested with a (known reliable) php script of my own, on a (known reliable) server available to me:

Code: Select all

   put URL "http://myDomain.com/myDir/myip.php" into myURL
   put myURL into myRes1
   
   put "http://myDomain.com/myDir/myip.php" into myURL
   put URL myURL into myRes2
   
   put myRes1 & CR & myRes2
That's what's in post 1, right?
I used LC 6.7.10 as well as 9.6.1, and every single time I got the same results (in this case, my public IP). Never a 403 or any other error, for a few thousands consecutive tests.

So, I'd check the php, the server logs, the IN connection (in this order).

Have fun!
All code published by me here was created with Community Editions of LC (thus is GPLv3).
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!

sphere
Posts: 1145
Joined: Sat Sep 27, 2014 10:32 am
Location: Earth, Except when i Jump

Re: Logic behind put URL or PUT URL into a variable

Post by sphere » Tue Dec 15, 2020 1:07 pm

AxWald wrote:
Tue Dec 15, 2020 11:31 am
So, I'd check the php, the server logs, the IN connection (in this order).
I will, and hopefully i will find the culprit.

sphere
Posts: 1145
Joined: Sat Sep 27, 2014 10:32 am
Location: Earth, Except when i Jump

Re: Logic behind put URL or PUT URL into a variable

Post by sphere » Sun Dec 20, 2020 3:02 pm

As I was not convinced that the PHP files would be the culprit, hence it worked before, so checked previous used files with the current ones. It were minor changes like tablenames etc. And since changing some in the LC script it worked, entering it directly in a browser also worked ok.
Also no errors related to this found in any log.
Did some testing and found that when putting the URL to the the folder where the PHP file resides into an global, causes the need for ().
If not using (), the global is simply forgotten.

Looked a bit better at the 403 error and saw the url not complete:
put URL global error.PNG
put URL global error.PNG (7.36 KiB) Viewed 8205 times
But it is available in the global variable:
put URL global error1.PNG
put URL global error1.PNG (3.51 KiB) Viewed 8205 times
Did some tests:

Code: Select all

global gMainUrl
on mouseUp pMouseButton
   local tA
answer gMainUrl & "getstuff.php" -- just to check the complete URL, it shows complete
   --put URL "https://website.nl/folder/folder/getstuff.php" into tA --works correct
   --put URL gMainUrl & "getstuff.php" into tA --gives Error 403 with https://website.nl/folder/folder/ in globalvariable
   put URL (gMainUrl & "getstuff.php") into tA --works correct with https://website.nl/folder/folder/ in globalvariable
   answer tA
end mouseUp
Is this a bug or is it the way it has to work? Either i'm fine, but then I think the Dictionary should be updated.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9802
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Logic behind put URL or PUT URL into a variable

Post by FourthWorld » Sun Dec 20, 2020 6:51 pm

Let's think about this statement from the LC engine's perspective:

Code: Select all

put URL gMainUrl & "getstuff.php" into tA
What's happening there is:
1. LC requests the value from the URL gMainURL
2. Then it concatenates "getstuff.php" to the return value from the URL
3. Then it puts the combined result into tA

The parens make the order of precedence explicit, as they would with match, forcing the engine to evaluate what's inside the parens first:
1. LC concatenate the two parts of the URL into a single string: gMainURL followed by "getstuff.php"
2. Then it requests the value from the complete URL
3. Then it puts the value returns from the request into tA

With text concatenation as with math, when in doubt you can make the order of precedence explicit with parentheses.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

sphere
Posts: 1145
Joined: Sat Sep 27, 2014 10:32 am
Location: Earth, Except when i Jump

Re: Logic behind put URL or PUT URL into a variable

Post by sphere » Sun Dec 20, 2020 7:52 pm

Ok, i understand how parentheses in this way helps and also to shorten the script.

Thanks for explaining Richard.

Post Reply

Return to “Internet”