wmannis / cl-gambol Goto Github PK
View Code? Open in Web Editor NEWBasic Prolog functionality for Common Lisp
License: Other
Basic Prolog functionality for Common Lisp
License: Other
The zebra problem in prolog is:
/* -*- Mode: prolog -*-
*
* This file for benchmarking against SWI Prolog.
*/
nextto(X, Y, List) :- iright(X, Y, List).
nextto(X, Y, List) :- iright(Y, X, List).
iright(Left, Right, [Left, Right | _]).
iright(Left, Right, [_ | Rest]) :- iright(Left, Right, Rest).
zebra(H, W, Z) :-
H = [house(norwegian, _, _, _, _), _, house(_, _, _, milk, _), _, _],
member(house(englishman, _, _, _, red), H),
member(house(spaniard, dog, _, _, _), H),
member(house(_, _, _, coffee, green), H),
member(house(ukrainian, _, _, tea, _), H),
iright(house(_, _, _, _, ivory), house(_, _, _, _, green), H),
member(house(_, snails, winston, _, _), H),
member(house(_, _, kools, _, yellow), H),
nextto(house(_, _, chesterfield, _, _), house(_, fox, _, _, _), H),
nextto(house(_, _, kools, _, _), house(_, horse, _, _, _), H),
member(house(_, _, luckystrike, oj, _), H),
member(house(japanese, _, parliaments, _, _), H),
nextto(house(norwegian, _, _, _, _), house(_, _, _, _, blue), H),
member(house(W, _, _, water, _), H),
member(house(Z, zebra, _, _, _), H).
/* This runs the query a single time:
* ?- zebra(Houses, WaterDrinker, ZebraOwner).
*/
zebra1(Houses, WaterDrinker, ZebraOwner) :-
zebra(Houses, WaterDrinker, ZebraOwner), !.
benchmark1 :-
flag(benchmark,_,0),
repeat,
zebra1(Houses, WaterDrinker, ZebraOwner),
flag(benchmark,N,N+1),
N = 1000,
!.
benchmark :- time(benchmark1).
I try my best but still can't get the correct code in cl-gambol:
;;;; cl-gambol-test.lisp
(ql:quickload 'gambol)
(in-package :gambol)
(*- (nextto ?x ?y ?list) (iright ?x ?y ?list))
(*- (nextto ?x ?y ?list) (iright ?y ?x ?list))
(*- (iright ?left ?right (?left ?right . ?rest)))
(*- (iright ?left ?right (?x . ?rest))
(iright ?left ?right ?rest))
(*- (zebra ?h ?w ?z)
(= ?h ((house norwegian ?? ?? ?? ??)
??
(house ?? ?? ?? milk ??) ?? ??))
(member (house englishman ?? ?? ?? red) ?h)
(member (house spaniard dog ?? ?? ??) ?h)
(member (house ?? ?? ?? coffee green) ?h)
(member (house ukrainian ?? ?? tea ??) ?h)
(iright (house ?? ?? ?? ?? ivory)
(house ?? ?? ?? ?? green) ?h)
(member (house ?? snails winston ?? ??) ?h)
(member (house ?? ?? kools ?? yellow) ?h)
(nextto (house ?? ?? chesterfield ?? ??)
(house ?? fox ?? ?? ??) ?h)
(nextto (house ?? ?? kools ?? ??)
(house ?? horse ?? ?? ??) ?h)
(member (house ?? ?? luckystrike oj ??) ?h)
(member (house japanese ?? parliaments ?? ??) ?h)
(nextto (house norwegian ?? ?? ?? ??)
(house ?? ?? ?? ?? blue) ?h)
(member (house ?w ?? ?? water ??) ?h)
(member (house ?z zebra ?? ?? ??) ?h))
;;; test but meet a condition
(?- (zebra ?houses ?water-drinker ?zebra-owner))
;;=>
;; The value (HOUSE NORWEGIAN #1=(*VAR* ?? -1) #1# #1# #1#)
;; is not of type
;; (OR (VECTOR CHARACTER) (VECTOR NIL) BASE-STRING SYMBOL
;; CHARACTER).
;; [Condition of type TYPE-ERROR]
;; Restarts:
;; 0: [RETRY] Retry SLIME REPL evaluation request.
;; 1: [*ABORT] Return to SLIME's top level.
;; 2: [ABORT] abort thread (#<THREAD "new-repl-thread" RUNNING {100682D733}>)
;; Backtrace:
;; 0: (SB-KERNEL:STRING=* #<unavailable argument> #<unavailable argument> #<unavailable argument> #<unavailable argument> #<unavailable argument> #<unavailable argument>) [tl,external]
;; 1: (EXPAND-LISP-HOOKS ((HOUSE NORWEGIAN #1=(*VAR* ?? -1) #1# #1# #1#) #1# (HOUSE #1# #1# #1# MILK #1#) #1# #1#) #(*UNDEFINED* *UNDEFINED* *UNDEFINED*))
;; 2: (DO-UNIFY #(MOLECULE (= (*VAR* ?H 0) (# #1=# # #1# #1#)) #(*UNDEFINED* *UNDEFINED* *UNDEFINED*)))
;; 3: (SEARCH-RULES (#(MOLECULE (= #1=# #) #2=#(*UNDEFINED* *UNDEFINED* *UNDEFINED*)) #(MOLECULE (LOP #) #2#) #(MOLECULE (LOP #) #2#) #(MOLECULE (LOP #) #2#) #(MOLECULE (LOP #) #2#) #(MOLECULE (IRIGHT # # #..
;; 4: (SEARCH-RULES (#(MOLECULE (ZEBRA # # #) #(# # #))) (#(MOLECULE (# # # # # # ...) #(*UNDEFINED* *UNDEFINED* *UNDEFINED*)) #(MOLECULE (# # # # # # ...) #(*UNDEFINED* *UNDEFINED* *UNDEFINED*)) #(MOLECULE..
;; 5: (SB-INT:SIMPLE-EVAL-IN-LEXENV (PL-SOLVE (QUOTE (#))) #<NULL-LEXENV>)
;; 6: (SB-INT:SIMPLE-EVAL-IN-LEXENV (?- (ZEBRA ?HOUSES ?WATER-DRINKER ?ZEBRA-OWNER)) #<NULL-LEXENV>)
;; 7: (EVAL (?- (ZEBRA ?HOUSES ?WATER-DRINKER ?ZEBRA-OWNER)))
;; 8: (SWANK::EVAL-REGION "(?- (zebra ?houses ?water-drinker ?zebra-owner)) ..)
A function to retract rules and facts would be very useful. Leave it in the
lisp realm, but export for
use in gambol procedures.
Original issue reported on code.google.com by [email protected]
on 8 Jul 2008 at 5:56
Perhaps being able to use multiple independent engines/rule bases would be
useful? Attached is a file implementing capturing all dynamic variables
into an object and a macro to use it with. If dynamic binding on SBCL work
like I think they do, this might even work under multithreading.
Original issue reported on code.google.com by [email protected]
on 24 Jul 2008 at 5:15
Attachments:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.