Re: (< @X 18) doesn't behave as expected with pilog (SOLVED)

2016-11-18 Thread Alexander Burger
He Eric,

> Done! Initial version here:
> http://picolisp.com/wiki/?accesstolispfunctionfrompilog

Great! Looks good!


> I hope it's a right place!

Yes, under "Documentation" it is optimal.

Thanks,
♪♫ Alex
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: (< @X 18) doesn't behave as expected with pilog (SOLVED)

2016-11-18 Thread CILz

Hi,

Done! Initial version here:

http://picolisp.com/wiki/?accesstolispfunctionfrompilog

I hope it's a right place!

Best,
Eric

Le 14/11/2016 à 15:55, Alexander Burger a écrit :

Wiki would be much better, wouldn't it?


--
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: (< @X 18) doesn't behave as expected with pilog

2016-11-14 Thread Alexander Burger
Hi Joe,

> range/3 seems to work as I expected. Should it not be used here?

Haha, right! Very good!

I was too much focused on the DB usage :)

♪♫ Alex
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: (< @X 18) doesn't behave as expected with pilog (SOLVED: short

2016-11-14 Thread Alexander Burger
Hi Eric,

On Sun, Nov 13, 2016 at 09:32:20PM +0100, CILz wrote:
> I've just created an account on the wiki however I think I can't add
> something in the reference part. I think that this how-to could fit very
> well here:
> 
> http://software-lab.de/doc/ref.html#pilog
> ... 

Very good examples and explanations!

However, I think for the general reference your text is a bit too
specialized, more like a tutorial. A (perhaps just short) article in the
Wiki would be much better, wouldn't it?

♪♫ Alex
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: (< @X 18) doesn't behave as expected with pilog

2016-11-14 Thread Joe Bogner
Hi Alex,

range/3 seems to work as I expected. Should it not be used here?

(be age (Paul 19) )
(be age (Kate 17) )

(be underage (@X)
  (age @X @Y)
  (range (0 . 18) @Y))

(? (underage @X) )
 @X=Kate





On Sat, Nov 12, 2016 at 10:44 AM, Alexander Burger  wrote:
> Hi Joe,
>
>> Untested, but what about using range/3 ?
>> http://software-lab.de/doc/refR.html#range/3
>
> Thanks! However, range/3 is probably not useful here. It is a rather
> specialized predicate for range checks in database queries.
>
> ♪♫ Alex
> --
> UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
--
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: (< @X 18) doesn't behave as expected with pilog (SOLVED: short

2016-11-13 Thread Alexander Burger
Hi Eric,

> Hum ! I just noticed that I may have been too friendly here, sorry. I wanted
> to say "Hi Alexander". My apologies. Best, Eric

Not at all! "Alex" is perfectly all right :)

♪♫ Alex
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: (< @X 18) doesn't behave as expected with pilog (SOLVED: short

2016-11-13 Thread CILz

Hi Alex,

I've just created an account on the wiki however I think I can't add 
something in the reference part. I think that this how-to could fit very 
well here:


http://software-lab.de/doc/ref.html#pilog

to illustrate the last part which starts with " Pilog can be called from 
Lisp and vice versa:"


After the last sentence and just before the horizontal rule, it could be 
word like this:


=

To illustrate this, let's say that you have those two facts in a Pilog 
database:


(be age (Paul 19) )
(be age (Kate 17) )

and that you want to find the person under 18.

In full Prolog you may have written something like this:

underage(X) :- age(X,Y), Y < 18.

however in Pilog the following rule:


(be underage (@X)
  (age @X @Y)
  (< @Y 18) )

won't work and the query:

(? (underage @X) )

will yield to 'NIL' instead of the expected result '@X=Kate' .

The reason is that '<' (less than) is not Pilog function but only a Lisp 
one in PicoLisp.


In order to embed a Lisp expression in a Pilog, you must use '^' 
operator. It causes the rest of the expression to be taken as Lisp. 
Then, inside the Lisp code you can in turn access Pilog-bindings with 
the '->' function.


Hence, in our case the Prolog rule above translates as:

(be underage (@X)
  (age @X @Y)
  (^ @ (< (-> @Y) 18)) )

In '(^ @ (< (-> @Y) 18))', '@' is an anonymous variable used to get the 
result. If you need to access the result you can bind it to a defined 
variable like in '(^ @B (+ (-> @A) 7))' where '@B' is now bound to '@A + 
7'.


You may prefer to define your own Pilog predicate in this particular 
case. Let's say that to avoid confusion, you want to create a Pilog 
predicate call 'less_than' to mimic the Lisp function '<':


(be less_than (@A @B)
  (^ @ (< (-> @A) (-> @B) )))

Then the Pilog rule becomes:

(be underage_1 (@X)
  (age @X @Y)
  (less_than @Y 18) )

and now:

(? (underage @X) )

yields to:

@X=Kate

which is the expected result.

=

Hope this helps.

Best,
Eric

Le 13/11/2016 à 15:47, Alexander Burger a écrit :

You can't be too young, I think. You could write it, and perhaps others
may improve it;)




Re: (< @X 18) doesn't behave as expected with pilog (SOLVED: short

2016-11-13 Thread Alexander Burger
Hi Eric,

> short how to. I haven't seen such a one on the wiki, so may be it can find
> its way there. However I'm too young here to take such a decision ;-)

You can't be too young, I think. You could write it, and perhaps others
may improve it ;)

♪♫ Alex
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: (< @X 18) doesn't behave as expected with pilog (SOLVED: short

2016-11-13 Thread CILz

Hi,

This is mostly a copy/paste of Alexander's answer below in the form of a 
short how to. I haven't seen such a one on the wiki, so may be it can 
find its way there. However I'm too young here to take such a decision ;-)


==

**How to access a Lisp function from Pilog**

Let's say that you have those two facts in a Pilog database:

(be age (Paul 19) )
(be age (Kate 17) )

and that you want to find the person under 18.

In full Prolog you may have written something like this:

underage(X) :- age(X,Y), Y < 18.

however in Pilog the following rule:


(be underage (@X)
  (age @X @Y)
  (< @Y 18) )

won't work and the query:

(? (underage @X) )

will yield to 'NIL' instead of the expected result '@X=Kate' .

The reason is that '<' (less than) is not Pilog function but only a Lisp 
one in PicoLisp.


In order to embed a Lisp expression in a Pilog, you must use '^' 
operator. It causes the rest of the expression to be taken as Lisp. 
Then, inside the Lisp code you can in turn access Pilog-bindings with 
the '->' function.


Hence, in our case the Prolog rule above translates as:

(be underage (@X)
  (age @X @Y)
  (^ @ (< (-> @Y) 18)) )

In '(^ @ (< (-> @Y) 18))', '@' is an anonymous variable used to get the 
result. If you need to access the result you can bind it to a defined 
variable like in '(^ @B (+ (-> @A) 7))' where '@B' is now bound to '@A + 7'.


You may prefer to define your own Pilog predicate in this particular 
case. Let's say that to avoid confusion, you want to create a Pilog 
predicate call 'less_than' to mimic the Lisp function '<':


(be less_than (@A @B)
  (^ @ (< (-> @A) (-> @B) )))

Then the Pilog rule becomes:

(be underage_1 (@X)
  (age @X @Y)
  (less_than @Y 18) )

and now:

(? (underage @X) )

yields to:

@X=Kate

which is the expected result. Et voià!

==

Best,

Eric

Le 12/11/2016 à 16:27, Alexander Burger a écrit :

Hi Eric,


(be underage (@X)
   (age @X @Y)
   (< @Y 18))

'<' is a Lisp function and not a Pilog rule. To embed a Lisp expression
in Pilog, you must use the '^' operator. It causes the rest of the
expression to be taken as Lisp, and inside the Lisp code you can in turn
access Pilog-bindings with the '->' function.

In the case above it should be something like

(^ @ (< (-> @Y) 18))

'@' is an anonymous variable here. If you want to bind the result of the
Lisp expression to a specific variable, it would be e.g.

(^ @X (+ (-> @N) 7))

This binds @X to @N + 7.


Of course, if you need '<' more often, you could define your own
predicate:

: (be < (@A @B)
   (^ @ (< (-> @A) (-> @B))) )
-> <

: (? (< 3 4))
-> T

: (? (< 4 2))
-> NIL

♪♫ Alex


--
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: (< @X 18) doesn't behave as expected with pilog

2016-11-12 Thread CILz

Hi Alexander,

Thanks for this answer. It works nicely. I will take my time to 
understand it thoroughly.


Best.


Le 12/11/2016 à 16:27, Alexander Burger a écrit :

Hi Eric,


(be underage (@X)
   (age @X @Y)
   (< @Y 18))

'<' is a Lisp function and not a Pilog rule. To embed a Lisp expression
in Pilog, you must use the '^' operator. It causes the rest of the
expression to be taken as Lisp, and inside the Lisp code you can in turn
access Pilog-bindings with the '->' function.

In the case above it should be something like

(^ @ (< (-> @Y) 18))

'@' is an anonymous variable here. If you want to bind the result of the
Lisp expression to a specific variable, it would be e.g.

(^ @X (+ (-> @N) 7))

This binds @X to @N + 7.


Of course, if you need '<' more often, you could define your own
predicate:

: (be < (@A @B)
   (^ @ (< (-> @A) (-> @B))) )
-> <

: (? (< 3 4))
-> T

: (? (< 4 2))
-> NIL

♪♫ Alex


--
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: (< @X 18) doesn't behave as expected with pilog

2016-11-12 Thread CILz
Thanks for this Joe. However I will need to investigate as I don't know 
Picolisp enough yet. My purpose is first to translate Prolog queries to 
Pilog in a Prologish/Pilogish way.



Le 12/11/2016 à 16:23, Joe Bogner a écrit :

Untested, but what about using range/3 ?
http://software-lab.de/doc/refR.html#range/3


--
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: (< @X 18) doesn't behave as expected with pilog

2016-11-12 Thread Alexander Burger
Hi Joe,

> Untested, but what about using range/3 ?
> http://software-lab.de/doc/refR.html#range/3

Thanks! However, range/3 is probably not useful here. It is a rather
specialized predicate for range checks in database queries.

♪♫ Alex
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: (< @X 18) doesn't behave as expected with pilog

2016-11-12 Thread Alexander Burger
Hi Eric,

> (be underage (@X)
>   (age @X @Y)
>   (< @Y 18))

'<' is a Lisp function and not a Pilog rule. To embed a Lisp expression
in Pilog, you must use the '^' operator. It causes the rest of the
expression to be taken as Lisp, and inside the Lisp code you can in turn
access Pilog-bindings with the '->' function.

In the case above it should be something like

   (^ @ (< (-> @Y) 18))

'@' is an anonymous variable here. If you want to bind the result of the
Lisp expression to a specific variable, it would be e.g.

   (^ @X (+ (-> @N) 7))

This binds @X to @N + 7.


Of course, if you need '<' more often, you could define your own
predicate:

   : (be < (@A @B)
  (^ @ (< (-> @A) (-> @B))) )
   -> <

   : (? (< 3 4))
   -> T

   : (? (< 4 2))
   -> NIL

♪♫ Alex
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


Re: (< @X 18) doesn't behave as expected with pilog

2016-11-12 Thread Joe Bogner
Untested, but what about using range/3 ?
http://software-lab.de/doc/refR.html#range/3



On Sat, Nov 12, 2016 at 9:59 AM, CILz  wrote:
> Hello,
>
> Let's say that I have those two facts in a pilog database:
>
> (be age (Paul 18))
> (be age (Vincent 17))
>
> I'm looking for the guy under 18 with this rule:
>
> (be underage (@X)
>   (age @X @Y)
>   (< @Y 18))
>
> If I ask (? (underage @X)) the result here is -> NIL where I expect to get
> @X=Vincent.
>
> If I modify the above rule with:
>
> (be underage (@X)
>   (age @X @Y)
>   (equal @Y 18))
>
> The same query (? (underage @X)) now gives @X=Paul which is the expected
> result.
>
> I'm sure I'm missing something in the first case but I don't know what. Any
> idea?
>
> Thanks,
>
> Eric
>
> --
> UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


(< @X 18) doesn't behave as expected with pilog

2016-11-12 Thread CILz

Hello,

Let's say that I have those two facts in a pilog database:

(be age (Paul 18))
(be age (Vincent 17))

I'm looking for the guy under 18 with this rule:

(be underage (@X)
  (age @X @Y)
  (< @Y 18))

If I ask (? (underage @X)) the result here is -> NIL where I expect to 
get @X=Vincent.


If I modify the above rule with:

(be underage (@X)
  (age @X @Y)
  (equal @Y 18))

The same query (? (underage @X)) now gives @X=Paul which is the expected 
result.


I'm sure I'm missing something in the first case but I don't know what. 
Any idea?


Thanks,

Eric

--
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe