我正在尝试从命令行执行序言脚本。我的尝试基于How to run SWI-Prolog from the command line?的发现 但这不适用于任何不平凡的示例(即除“ hello world”示例以外的任何示例)。
:- initialization(main, program).
main :-
parent(pam,bob).
parent(tom,bob).
parent(tom,liz).
parent(bob,ann).
parent(bob,pat).
parent(pat,jim).
parent(X,jim).
halt.
我用$ swipl -q -s temp.p
执行此操作,并收到以下错误消息
Warning: temp.p:10:
Singleton variables: [X]
ERROR: temp.p:11:
No permission to modify static procedure `halt/0'
Defined at /opt/local/lib/swipl/boot/init.pl:3867
我如何从命令行执行此操作,获取结果,但不保留给代表?
答案 0 :(得分:1)
您最大的问题是您的源代码有很多问题。我已经像这样修复了它们:
local.INFO: array (
'CODIGO' => 'IS2117-1103WF',
'SKU' => 'IS2117-1103WF-GR',
'ETIQUETAS DE RELACION' => 'Maleta, Case, ISP, Foam',
'PROVEEDOR' => 'PELICAN',
'DESCRIPCION - ESPAÑOL' => 'Maleta ISP, Con Foam, Equipadas con un anillo de sellado esponjoso de silicona y válvulas de descarga de presión',
'DESCRIPCION - INGLES' => 'IS2117-1103, W/F, P127-131, GRY',
'DESCUENTO' => 0,
'COLOR-AB' => 'GR',
'COLOR' => 'GREY',
'MARCA' => 'PELICAN',
'FOB' => 714.950000000000045474735088646411895751953125,
'FI COSTA RICA' => 0.81999999999999995115018691649311222136020660400390625,
'Margen COSTA RICA' => 0.6999999999999999555910790149937383830547332763671875,
'FI NICARAGUA' => 0.8000000000000000444089209850062616169452667236328125,
'Margen NICARAGUA' => 0.65000000000000002220446049250313080847263336181640625,
'FI HONDURAS' => 0.7800000000000000266453525910037569701671600341796875,
'Margen HONDURAS' => 0.59999999999999997779553950749686919152736663818359375,
'Costo/Precio CR' => 1245.557491289198878803290426731109619140625,
'Costo/Precio Nic' => 1374.90384615384618882671929895877838134765625,
'Costo/Precio Hn' => 1527.670940170940184543724171817302703857421875,
'PRECIO COSTA RICA' => 1245,
'PRECIO NICARAGUA' => 1375,
'PRECIO HONDURAS' => 1530,
'lista-CARACTERISTICAS GENERALES-Detalle 1' => 'Temperatura Mínima: -20° F (-29 ° C)',
'lista-CARACTERISTICAS GENERALES-Detalle 2' => 'Temperatura Máxima: 140° F (60 ° C)',
'lista-CARACTERISTICAS GENERALES-Detalle 3' => 'Volumen Interior: 2.89 ft³ (0.082 m³)',
'tabla-Caracteristicas tecnicas-Dimensiones (pulgadas)' => '24x20x17',
'tabla-Caracteristicas tecnicas-Anchura (pulgadas)' => 24,
'tabla-Caracteristicas tecnicas-Longitud (pulgadas)' => 20,
'tabla-Caracteristicas tecnicas-Altura (pulgadas)' => 17,
'lista-Caracteristicas de materiales-Detalle 1' => 'Cuerpo: Polietileno',
'lista-Caracteristicas de materiales-Detalle 2' => 'Cuerpo de Compensación: Aluminio',
'lista-Caracteristicas de materiales-Detalle 3' => 'Cierre: Acero',
'lista-Caracteristicas de materiales-Detalle 4' => 'Pasadores: Acero Inoxidable / Aluminio',
'tabla-PESO-Libras ' => 26.5,
)
local.INFO: new factor {"country_id":1,"product_id":704,"margin":0.6999999999999999555910790149937383830547332763671875,"fi":0.81999999999999995115018691649311222136020660400390625,"id":2110}
local.INFO: fi 0.82
local.INFO: margen 0.7
local.INFO: price {"country_id":1,"product_id":704,"price":1245,"id":2110}
local.INFO: price: 1245
local.INFO: new factor {"country_id":2,"product_id":704,"margin":0.65000000000000002220446049250313080847263336181640625,"fi":0.8000000000000000444089209850062616169452667236328125,"id":2111}
local.INFO: fi 0.8
local.INFO: margen 0.65
local.INFO: price {"country_id":2,"product_id":704,"price":1375,"id":2111}
local.INFO: price: 1375
local.INFO: new factor {"country_id":3,"product_id":704,"margin":0.59999999999999997779553950749686919152736663818359375,"fi":0.7800000000000000266453525910037569701671600341796875,"id":2112}
local.INFO: fi 0.78
local.INFO: margen 0.6
local.INFO: price {"country_id":3,"product_id":704,"price":1530,"id":2112}
local.INFO: price: 1530
现在程序没有错误,您可以通过在命令行上提供目标来执行它而无需返回到REPL:
parent(pam,bob).
parent(tom,bob).
parent(tom,liz).
parent(bob,ann).
parent(bob,pat).
parent(pat,jim).
main :-
parent(X,jim),
format('~a is the parent of jim~n', [X]),
halt.