Anonymous Variables in Imperative Languages

09/24/2017 ∙ by Keehang Kwon, et al. ∙ DONG-A UNIVERSITY ALLRIGHTS RESERVED 0

In this paper, we bring anonymous variables into imperative languages. Anonymous variables represent don't-care values and have proven useful in logic programming. To bring the same level of benefits into imperative languages, we describe an extension to C wth anonymous variables.

READ FULL TEXT VIEW PDF
POST COMMENT

Comments

There are no comments yet.

Authors

page 1

page 2

page 3

page 4

This week in AI

Get the week's most popular data science and artificial intelligence research sent straight to your inbox every Saturday.

1 Introduction

The notion of anonymous variables was introduced in logic programming. Anonymous variables represent don’t-care values. As we shall see later, they provide some convenience to programming. This paper aims to bring anonymous variables into imperative languages. Thus we allow the symbol which denotes an anonymous variable. To see some use of anonymous variables, let us consider the following procedure which produces the amount of the tuition of a student with major .

tuition(x,m) =
case medical : amount = $10K;
case english : amount = $5K;
case physics : amount = $5K;

Note that the above program is independent of . To represent this, we replace the above with

tuition(_,m) =
case medical : amount = $10K;
case english : amount = $5K;
case physics : amount = $5K;

which is an abbreviation of

tuition(x,m) =
case medical : amount = $10K;
case english : amount = $5K;
case physics : amount = $5K;

where is called a universal quantifier111This concept was originally introduced in [2], but with different notations. For example, the blind universal quantifier is denoted by .. The main difference between and is that, in the former, the instantiation of will be visible to the user and will be recorded in the execution trace, while in the latter, it will.

Now consider the following procedure call.

Then the machine will print “$10K” as usual.

We also introduce its counterpart where is a procedure call. In this case becomes an anonymous variable.

Implementing anonymous variables is not too difficult. Below we describe a modest method to bring anonymous variables into imperative language. During execution anonymous variables will be replaced by some value. Choosing the proper value for anonymous variables is often not trivial. Typically anonymous variables will be replaced by uninstantiated variables. These variables will be instanced later when enough information is gathered. This process is typically known as . Unification process will not be described here and we refer [6] to the reader.

2 The Language

The language is a subset of the core (untyped) C with some extensions. It is described by - and -formulas given by the syntax rules below: In the above, represents a head of an atomic procedure definition of the form . A -formula is a set of procedure declarations.

In the execution, a -formula will function as a statement and a set of -formulas enhanced with the machine state (a set of variable-value bindings) will constitute a program. Thus, a program is a union of two disjoint sets, i.e., where represents the machine state. is initially empty and will be updated dynamically during execution via the assignment statements.

We will present an interpreter for our language via natural semantics [1]. It alternates between the execution phase and the backchaining phase. In the execution phase (denoted by ), it executes a statement with respect to and produce a new program by reducing to simpler forms. The rules (7)-(10) deal with this phase. If becomes a procedure call, the machine switches to the backchaining mode. This is encoded in the rule (6). In the backchaining mode (denoted by ), the interpreter tries to find a matching procedure for a procedure call inside the module by decomposing into a smaller unit (via rule (4)-(5)) and reducing to its instance (via rule (2),(3)) and then backchaining on the resulting definition (via rule (1)). To be specific, the rule (2) basically deals with argument passing: it eliminates the universal quantifier in by picking a value for so that the resulting instantiation, , matches the procedure call . The notation  seqand  denotes the sequential execution of two tasks. To be precise, it denotes the following: execute and execute sequentially. It is considered a success if both executions succeed. Similarly, the notation  parand  denotes the parallel execution of two tasks. To be precise, it denotes the following: execute and execute in any order. It is considered a success if both executions succeed. The notation denotes reverse implication, i.e., .

Definition 1.  Let be a statement and let be a program. Then the notion of executing and producing a new program – is defined as follows:


  • . % A matching procedure for is found.


  • . % argument passing. Instantiation will be recorded.


  • . % argument passing. Instantiation will not be recorded.


  • . % look for a matching procedure in .


  • . % look for a matching procedure in

  • parand . % is a procedure call

  • . % is an anonymous variable.

  • . % True is always a success.

  • .
    % In the assignment statement, it evaluates to get . The symbol denotes a set union but in will be replaced by .


  • seqand . % a sequential composition

If has no derivation, then the interpreter returns the failure.

3 Examples

Let us consider again the example in the Introduction section.

tuition(x,m) =
case medical : amount = $10K;
case english : amount = $5K;
case physics : amount = $5K;

Now consider the following procedure call.

Note that _ is used in the above, as there is no need to specify a student. The above can be understood as an abbreviation of

4 Conclusion

In this paper, we have presented a notion of anonymous variables in the setting of imperative languages. We introduce for anonymous variables in procedure declarations and for anonymous variables in procedure calls. Anonymous variables provide some convenience to programmers.

References

  • [1] G. Kahn, “Natural Semantics”, In the 4th Annual Symposium on Theoretical Aspects of Computer Science, LNCS vol. 247, 1987.
  • [2] G. Japaridze, “Introduction to computability logic”, Annals of Pure and Applied Logic, vol.123, pp.1–99, 2003.
  • [3] G. Japaridze, “Sequential operators in computability logic”, Information and Computation, vol.206, No.12, pp.1443-1475, 2008.
  • [4] K. Kwon, S. Hur and M. Park, “Improving Robustness via Disjunctive Statements in Imperative Programming”, IEICE Transations on Information and Systems, vol.E96-D,No.9, pp.2036-2038, September, 2013.
  • [5] J. Hodas and D. Miller, “Logic Programming in a Fragment of Intuitionistic Linear Logic”, Information and Computation, vol.110, No.2, pp.327-365, 1994.
  • [6] D. Miller, G. Nadathur, F. Pfenning, and A. Scedrov, “Uniform proofs as a foundation for logic programming”, Annals of Pure and Applied Logic, vol.51, pp.125–157, 1991.
  • [7] D. Miller, G. Nadathur, Programming with higher-order logic, Cambridge University Press, 2012.