Skip to Content.
Sympa Menu

k-user - [K-user] Global Variable and Functions

k-user AT lists.cs.illinois.edu

Subject: K-user mailing list

List archive

[K-user] Global Variable and Functions


Chronological Thread 
  • From: soha hussein <husseinsoh AT gmail.com>
  • To: "k-user AT cs.uiuc.edu" <k-user AT cs.uiuc.edu>
  • Subject: [K-user] Global Variable and Functions
  • Date: Mon, 12 Jan 2015 11:50:09 +0300
  • List-archive: <http://lists.cs.uiuc.edu/pipermail/k-user/>
  • List-id: <k-user.cs.uiuc.edu>

Hello,

I have a problem and I am wondering if you can help me. What i want to do is
actually very simple. I want a global variable (counter) and a function (Exp
-> Exp) that checks the counter and update its value accordingly.

What I have done is I created the counter in a new cell <c>C:Int<c>, but then
writing a function rule like:

rule <k> f(C) => E:Exp </k>
<c>C:Int => C +Int 1</c>


does not work, because K will match it when f is on top of the computation,
which I do not want, i want it to apply wherever it exists.


I tried another way, I changed the function into a new internal expression
construct, but then I had a problem of defining the KResult; since the f: Exp
-> Exp then KResult will include Exp, but then computation on Exp will stop
since it is in the Exp.


I am looping in the same issue over and over, I have another way to do it,
but it is so complicated for the purpose I want it.


So my questions are:

1. Can anybody tell me how to create a global counter and have it accessible
through other functions?
2. Are there other ways of defining a global variable?
3. Is there a built in counter, like fresh or random?
4. Are there any other way of defining terminals other than including them in
KResult?
5. Can I call a K program from another? How?



Thanks

Soha






Archive powered by MHonArc 2.6.16.

Top of Page