k-user AT lists.cs.illinois.edu
Subject: K-user mailing list
List archive
- From: Daniele Filaretti <dfilaretti AT gmail.com>
- To: "k-user AT cs.uiuc.edu" <k-user AT cs.uiuc.edu>
- Subject: [K-user] resolving variable names inside double quoted strings (as in PHP)
- Date: Fri, 1 Feb 2013 13:25:18 +0000
- List-archive: <http://lists.cs.uiuc.edu/pipermail/k-user/>
- List-id: <k-user.cs.uiuc.edu>
Hi all,
In PHP (the language I'm trying to define in K) when a variable name occurs
in a string (variable names always start with $) the value of that variable
is found in the environment and printed into the string. For example:
> $x = "Daniele";
> echo "Hello $x!"
>
> out>> "Hello Daniele!"
Until now I ignored this in my definition - i.e., I'm using builtin strings
that K offer, and I can achieve the same with (that is also legal in PHP):
> $x = "Daniele";
> echo "Hello " . $x . "!"
>
> out>> "Hello Daniele!"
However, I noticed that the feature is heavily used (of course, as it's a
very handy shortcut), so I decided to add it.
I'm currently having a look at the C definition by Chucky Ellison, as I think
something similar has to be done for C's 'printf". However, it seems that
their solution is very low level (scanning a string character by character
and defining some kind of state machine I guess), and perhaps I don't need
that level of detail.
Ideally, all I need is just something like a string tokenizer.
For example if my string is
> "Hello $x!"
I would like to obtain a list (containing strings and variables) :
> ["Hello", $x, "!"]
with this list I could easily print the elements that are already strings,
and evaluate the variable names before printing them as well (using my
already defined printing function for strings -- sending to it the elements
of my list one by one).
Any ideas? Comments? Suggestions?
Thanks a lot to everyone!
Cheers,
Daniele
- [K-user] resolving variable names inside double quoted strings (as in PHP), Daniele Filaretti, 02/01/2013
- Re: [K-user] resolving variable names inside double quoted strings (as in PHP), Guth, Dwight, 02/01/2013
- Re: [K-user] resolving variable names inside double quoted strings (as in PHP), Rosu, Grigore, 02/01/2013
- Re: [K-user] resolving variable names inside double quoted strings (as in PHP), Daniele Filaretti, 02/01/2013
- Re: [K-user] resolving variable names inside double quoted strings (as in PHP), Radu Mereuta, 02/01/2013
- Re: [K-user] resolving variable names inside double quoted strings (as in PHP), Daniele Filaretti, 02/01/2013
- Re: [K-user] resolving variable names inside double quoted strings (as in PHP), Radu Mereuta, 02/01/2013
- Re: [K-user] resolving variable names inside double quoted strings (as in PHP), Daniele Filaretti, 02/01/2013
- Re: [K-user] resolving variable names inside double quoted strings (as in PHP), Rosu, Grigore, 02/01/2013
- Re: [K-user] resolving variable names inside double quoted strings (as in PHP), Mark Hills, 02/01/2013
- Re: [K-user] resolving variable names inside double quoted strings (as in PHP), Daniele Filaretti, 02/01/2013
- Re: [K-user] resolving variable names inside double quoted strings (as in PHP), Guth, Dwight, 02/01/2013
Archive powered by MHonArc 2.6.16.