Skip to Content.
Sympa Menu

k-user - [K-user] (no subject)

k-user AT lists.cs.illinois.edu

Subject: K-user mailing list

List archive

[K-user] (no subject)


Chronological Thread 
  • From: Ömer Sinan Ağacan <omeragacan AT gmail.com>
  • To: k-user AT cs.uiuc.edu
  • Subject: [K-user] (no subject)
  • Date: Sat, 17 Aug 2013 23:17:42 +0300
  • List-archive: <http://lists.cs.uiuc.edu/pipermail/k-user/>
  • List-id: <k-user.cs.uiuc.edu>

Dear K users and developers,

I hope this is the right place to ask user questions. I just started
learning K and I'm having trouble understanding some parts. I actually
have a huge list of questions in mind but for now I want to ask only a
portion of them. Please excuse me if I'm sending this to an
inappropriate list.

Let's say I have this K program: (btw, sorry if I'm using some
terminology wrong and please correct me if I'm wrong. this is my first
K code ever)


module CONCAT-SYNTAX

syntax Concat ::= Concat1 ";" Concat
| "end"

syntax Concat1 ::= Id
| "[" Concat "]" // quotation
| Int
| "printSomethingRandom"

endmodule

module CONCAT

imports CONCAT-SYNTAX

configuration
<k> $PGM:Concat </k>
<out stream="stdout"> .List </out>
<someList> .List </someList>
<someMap> .Map </someMap>

rule <k> (printSomethingRandom;Cs) => Cs </k>
<out> ... . => ListItem(N) </out>
<someList> ... . => ListItem(N) </someList>
when fresh(N:Nat)

rule <k> (I:Id;Cs) => Cs </k>
<someList> ... . => ListItem(I) </someList>

rule <k> (I:Int;Cs) => Cs </k>
// if I remove the part below this rule works fine
<someMap> ... I |-> (_ => N) ... </someMap>
when fresh(N:Nat)

rule <k> end => . </k>

endmodule


(this is going to be a concatenative language like Forth, PostScript,
Joy, Cat, Factor etc. when it's done)

Now let me list my questions about this program:

* Let's say I changed the separator in Concat syntax from ";" to "
". Now how can I match it in rules? Simply changing ; characters with
` ` (space character) fails with "syntax error". Interestingly, if I
change it with "-" instead of " ", it works fine. I don't understand
how to use space character in patterns in rules.

* Is there a reference manual etc. for matching rules to manipulate
data structures like Map/List/Bag etc.? In this code, for some reason
3. rule doesn't work. This is probably because of a mistake in
matching syntax in <someMap> part of the rule. (because removing that
part makes it work) I copied that code from Imp implementation which
is defined in K tutorials, but for some reason same syntax doesn't
work for me.

* Let's say I'm running this program:

➜ concat cat test.con
printSomethingRandom;thisIsAnIdentifier;10;end
➜ concat krun --no-config test.con
➜ concat krun test.con
<k>
10 ; end
</k>
<someList>
ListItem(#symNat(1))
ListItem(thisIsAnIdentifier)
</someList>
<out>
ListItem(#ostream ( 1 ))
ListItem(#buffer ( "" ))
ListItem(#symNat(1))
</out>
<someMap>
.Map
</someMap>

as you can see, even though I'm adding some elements to out list,
and out configuration is marked as an output stream, this program
doesn't really print anything. Why is that?

* Let's say I'm using built-in list syntax instead of `Concat1 ";"
Concat` syntax I used in first syntax declaration: `List{Concat1,
";"}`. Now how should I change my rules in order to match this new
syntax?


Thanks,


---
Ömer Sinan Ağacan
http://osa1.net





Archive powered by MHonArc 2.6.16.

Top of Page