Re: Can i make a variable like those in imperative language ?



In message <d6dkkc$f2p$1@xxxxxxxxxxxxxxxxx>, SoULiaNe <cubix_car@xxxxxxxx> writes
Hi, sorry for the newbie question and bad english...

I want to have a program parameter in Prolog just like what we can do in C with something like "#define N 5". It is not necessary to be a constant, so a variable can be suffisant... but how to make a variable in Prolog ? I mean a variable like those in imperatives languages.

Thank you !

I once wrote a module that added this ability to ESI's Prolog2. It could also be used to add it to other Prologs, but to install it you need to be able to intercept the Prolog system's parser.


It did not work at the string level (as it does in C) but at the structure level. It used # as a left operator, so you could #define the structure #n to be 5. Then the system's parser replaced #n by 5 wherever it found it.

I found it very useful, once I had written it. I am surprised that most Prolog systems don't support something like it.

Nick
--
Nick Wedd    nick@xxxxxxxxxxxxx
.



Relevant Pages

  • Re: Java to Prolog and assert/retract
    ... Nick Wedd wrote: ... > knowledge of Prolog tells me that ... > is clumsy. ... because a reasonable name for the objects you deal with enhances readability. ...
    (comp.lang.prolog)
  • Re: newbie question
    ... Nick Wedd writes: ... >> I wrote a code finding ways from one point to another in count. ... I need the best (shortest). ... In Prolog, once a variable has a value, it keeps that value. ...
    (comp.lang.prolog)
  • Re: Prolog IV
    ... PROLOG II+ also features an incremental garbage collector, a sophisticated environment and a double syntax. ... Prolog II + pour Power Mac ... Nick Wedd nick@xxxxxxxxxxxxx ...
    (comp.lang.prolog)
  • Re: Again on polymorphism.
    ... In message, Nick Wedd ... >>But I seem to understand this is not common practice in prolog? ... Does setPosition/3 use retract ... fact with A in it and assert a fact with B in it. ...
    (comp.lang.prolog)
  • Re: Can i make a variable like those in imperative language ?
    ... sorry for the newbie question and bad english... ... > I want to have a program parameter in Prolog just like what we can do ... And you have to call the 'set_dynamic' predicate somewhere in your ...
    (comp.lang.prolog)