Skip to Content.
Sympa Menu

k-user - Re: [K-user] resolving variable names inside double quoted strings (as in PHP)

k-user AT lists.cs.illinois.edu

Subject: K-user mailing list

List archive

Re: [K-user] resolving variable names inside double quoted strings (as in PHP)


Chronological Thread 
  • From: Daniele Filaretti <dfilaretti AT gmail.com>
  • To: Mark Hills <Mark.Hills AT cwi.nl>
  • Cc: k-user AT cs.uiuc.edu
  • Subject: Re: [K-user] resolving variable names inside double quoted strings (as in PHP)
  • Date: Fri, 1 Feb 2013 14:56:23 +0000
  • List-archive: <http://lists.cs.uiuc.edu/pipermail/k-user/>
  • List-id: <k-user.cs.uiuc.edu>

On 1 Feb 2013, at 14:38, Mark Hills
<Mark.Hills AT cwi.nl>
wrote:

> In the parser we are using in our work on PHP, a string such as this gives
> us back a special form of string which is actually a list of string pieces,
> each of which is an individual expression. So, you would get back a list of
> a string literal "Hello ", an expression $x, and a string literal "!". If
> you do it this way, you also don't need to worry about the distinction
> between single-quoted and double-quoted strings inside the semantics, the
> parser can give you the right representation.

Hi Mark,
thanks for your reply.
And yep, that would be great, and it's exactly what I would like to have.

> The question would be whether you could define such syntax rules inside K
> (that I cannot answer).

Well, if I understand correctly, Radu is working on it! :)

Daniele

> ----- Original Message -----
> From: "Daniele Filaretti"
> <dfilaretti AT gmail.com>
> To:
> k-user AT cs.uiuc.edu
> Sent: Friday, February 1, 2013 2:25:18 PM
> Subject: [K-user] resolving variable names inside double quoted strings (as
> in PHP)
>
> 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 mailing list
> k-user AT cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/k-user






Archive powered by MHonArc 2.6.16.

Top of Page