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: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

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

Logic behind put URL or PUT URL into a variable

Post by sphere » Wed Dec 02, 2020 10:02 pm

Hi,

i don't understand the logic behind this:

This does not work:

Code: Select all

put URL "https://mywebsite.com/folder/getinfo.php" into tUrl
answer tUrl
Gives Error 403 forbidden

This works:

Code: Select all

put "https://mywebsite.com/folder/getinfo.php" into tUrl
put URL tUrl into tThis
answer tThis
Now please note that i already knew this in the back of my mind as i used it before.
But when busy and using the first approach you start thinking what the h*ll is wrong.
Waisting time to figure out again, oh yeah put it in a variable.

Now what is the logic for the first approach not to work and the 2nd does, just by putting the url in a variable?

Aint that just a bug?

Regards,
Sphere

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3202
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

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

Post by mwieder » Wed Dec 02, 2020 10:22 pm

Do parentheses help?

Code: Select all

put URL ("https://mywebsite.com/folder/getinfo.php") into tUrl

sphere
Posts: 1109
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 » Thu Dec 03, 2020 8:41 pm

Yes it does.
Thanks for that.
mmm, i did not know. Can't also find it not back in the dictionary that way.

How come that does work?

Thanks!

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3202
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

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

Post by mwieder » Fri Dec 04, 2020 1:30 am

Not sure. The URL operator is a bit weird in that it acts like a function but it's not really.
I've just gotten into the habit of thinking of it as a function and thus putting parentheses around the argument.
Helps keep me out of trouble. :P

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 8299
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 » Fri Dec 04, 2020 3:17 am

It's so unlike how the rest of the language works I'm tempted to consider it a bug.
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3202
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

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

Post by mwieder » Fri Dec 04, 2020 3:59 am

There's been some talk about this before. The parentheses aren't always needed, but when they are they are.
...and you know if it's a bug it won't get fixed because of compatibility.

SparkOut
Posts: 2358
Joined: Sun Sep 23, 2007 4:58 pm

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

Post by SparkOut » Fri Dec 04, 2020 8:37 am

mwieder wrote:
Fri Dec 04, 2020 1:30 am
Not sure. The URL operator is a bit weird in that it acts like a function but it's not really.
I've just gotten into the habit of thinking of it as a function and thus putting parentheses around the argument.
Helps keep me out of trouble. :P
Me too. I have always put parentheses around the argument. On Windows I don't know if it fails on every occasion without, but it has been a long, long time since I tried. It is very easy to treat like a function - you don't use URL like a command after all, you always get it or put the returned value into a container. So just like

Code: Select all

get myFunction tVal
doesn't behave nicely I treat URL the same way.

sphere
Posts: 1109
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 » Fri Dec 04, 2020 5:05 pm

Thank you all, I won't file a bug report for "Compatibility" sakes :)
So now we know this works and it's findable here on the forum, best to leave it.

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

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

Post by PaulDaMacMan » Tue Dec 08, 2020 12:59 am

FourthWorld wrote:
Fri Dec 04, 2020 3:17 am
It's so unlike how the rest of the language works I'm tempted to consider it a bug.
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, because in one you're asking to put the container itself into another container rather then asking to put the contents of the container into the second container. The parentheses tells the interpreter to evaluate what's inside first, a URL container, which results in the contents?

I use URL for reads & writes to local disc more than anything else, as a shortcut alternative to sequence of lines: open file, x read from / write to file x, close file x). Not sure if it's faster or not, but it seems faster, would have to do some speed tests to see if there's an advantage of one way over the other. Using URL obviously is less lines of code to type.
My LCB Repos: https://github.com/PaulMcClernan/

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 8299
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 1:45 am

PaulDaMacMan wrote:
Tue Dec 08, 2020 12:59 am
The parentheses tells the interpreter to evaluate what's inside first, a URL container, which results in the contents?
In my mind the "URL" keyword does that.
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5786
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

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

Post by jacque » 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."
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 8299
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 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.
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3202
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

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

Post by mwieder » Tue Dec 08, 2020 10:00 pm

Yes, the 'container' definition makes sense to me. But there isn't (or at least there shouldn't be) a difference between

card "xyzzy"
and
card ("xyzzy")

and the same might hold for

url "some://url"
and
url ("some://url")

...but the anomaly I see here is more that the parentheses are *sometimes* required for the url operator, and I don't know what the differentiating syntactical context is.

SparkOut
Posts: 2358
Joined: Sun Sep 23, 2007 4:58 pm

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

Post by SparkOut » Tue Dec 08, 2020 10:36 pm

It's still easier to pretend it's a function.
You don't

Code: Select all

get card "xyzzy"
or

Code: Select all

put card "xyzzy" into field "plugh"
but in the same way that you

Code: Select all

put myFunction("maze") into tBedquilt
you would also

Code: Select all

put URL ("http://www.colossalcave_fake_url") into tSmallBrickBuilding
I concur that you can

Code: Select all

put field "plugh" into tBedquilt
without parentheses, and

Code: Select all

get card ("twisty_little_passages")
is just as useless with parentheses as without, so it is anomalous (but a card object is not a "container" per se).

OK, I admit I really posted this for the adventure game refs, but isn't it easier to pretend that the URL keyword behaves like a function? Certainly not a command, anyway.

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3202
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

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

Post by mwieder » Tue Dec 08, 2020 11:29 pm

I *do* pretend it's a function, and thus always put the parentheses around the parameter.

If I had to guess because I'm not motivated enough to test it, I'd say the problem without parentheses comes from the parser attempting to dereference an external FQDN before evaluating the 'URL' operator. Thus

get URL "http://zork.org/key.php"
would generate an error while a local reference
get URL "file://someFolder/myFile"
would not.

Post Reply

Return to “Internet”