Page 1 of 2
Logic behind put URL or PUT URL into a variable
Posted: Wed Dec 02, 2020 10:02 pm
by sphere
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
Re: Logic behind put URL or PUT URL into a variable
Posted: Wed Dec 02, 2020 10:22 pm
by mwieder
Do parentheses help?
Code: Select all
put URL ("https://mywebsite.com/folder/getinfo.php") into tUrl
Re: Logic behind put URL or PUT URL into a variable
Posted: Thu Dec 03, 2020 8:41 pm
by sphere
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!
Re: Logic behind put URL or PUT URL into a variable
Posted: Fri Dec 04, 2020 1:30 am
by mwieder
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.

Re: Logic behind put URL or PUT URL into a variable
Posted: Fri Dec 04, 2020 3:17 am
by FourthWorld
It's so unlike how the rest of the language works I'm tempted to consider it a bug.
Re: Logic behind put URL or PUT URL into a variable
Posted: Fri Dec 04, 2020 3:59 am
by mwieder
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.
Re: Logic behind put URL or PUT URL into a variable
Posted: Fri Dec 04, 2020 8:37 am
by SparkOut
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.
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
doesn't behave nicely I treat URL the same way.
Re: Logic behind put URL or PUT URL into a variable
Posted: Fri Dec 04, 2020 5:05 pm
by sphere
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.
Re: Logic behind put URL or PUT URL into a variable
Posted: Tue Dec 08, 2020 12:59 am
by PaulDaMacMan
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.
Re: Logic behind put URL or PUT URL into a variable
Posted: Tue Dec 08, 2020 1:45 am
by FourthWorld
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.
Re: Logic behind put URL or PUT URL into a variable
Posted: Tue Dec 08, 2020 5:24 pm
by jacque
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."
Re: Logic behind put URL or PUT URL into a variable
Posted: Tue Dec 08, 2020 6:03 pm
by FourthWorld
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.
Re: Logic behind put URL or PUT URL into a variable
Posted: Tue Dec 08, 2020 10:00 pm
by mwieder
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.
Re: Logic behind put URL or PUT URL into a variable
Posted: Tue Dec 08, 2020 10:36 pm
by SparkOut
It's still easier to pretend it's a function.
You don't
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
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.
Re: Logic behind put URL or PUT URL into a variable
Posted: Tue Dec 08, 2020 11:29 pm
by mwieder
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.