我有一个这样创建的表:
CREATE TABLE IF NOT EXISTS DIM_Jour (
jour_id uuid NOT NULL,
AAAA int,
MM int,
JJ int,
Jour_Semaine int,
Num_Semaine int,
PRIMARY KEY (jour_id)
);
Run Code Online (Sandbox Code Playgroud)
我正在尝试手动插入一些值以进行测试。我知道最终我需要使用 UUID 生成器。
INSERT INTO DIM_Jour (jour_id, AAAA, MM, JJ, Jour_Semaine, Num_Semaine) VALUES (
292a485f-a56a-4938-8f1a-bbbbbbbbbbb1,
2020,
11,
19,
4,
47
);
Run Code Online (Sandbox Code Playgroud)
我收到此错误(或类似错误)
ERROR: syntax error at or near "a485f"
LINE 3: 292a485f-a56a-4938-8f1a-bbbbbbbbbbb1,
^
Run Code Online (Sandbox Code Playgroud)
我已经尝试过Postgres 文档中提到的不同格式,但似乎它不排除任何格式。这是一个愚蠢的语法问题还是我在这里遗漏了一些东西?正确的语法是什么?
上下文:我有一个文本文件,fr.txt
其中包含3列文本:
65 A #\A
97 a #\a
192 À #\latin_capital_letter_a_with_grave
224 à #\latin_small_letter_a_with_grave
etc...
Run Code Online (Sandbox Code Playgroud)
我想创建一个函数来读取第一个(也最终是第三个)列并将其写入另一个名为的文本文件中alphabet_code.txt
.
到目前为止,我有这个功能:
(defun alphabets()
(setq source (open "fr.txt" :direction :input :if-does-not-exist :error))
(setq code (open "alphabet_code.txt" :direction :output :if-does-not-exist :create :if-exists :supersede))
(loop
(setq ligne (read-line source nil nil))
(cond
((equal ligne nil) (return))
(t (print (read-from-string ligne) code))
)
)
(close code)
(close source)
)
Run Code Online (Sandbox Code Playgroud)
我的问题:
我真的不明白读取线功能的参数如何.我已阅读此文档,但对我来说仍然很模糊.如果有人会有非常简单的例子,那会有所帮助.
使用当前代码,我收到此错误:*** - read: input stream #<input string-input-stream> has reached its end …
我想写会起作用方法一样微距功能时, Common Lisp中:
(defmacro when2 (&rest args)
`(if (car (quote ,args)) (progn (quote ,args)) nil)
)
Run Code Online (Sandbox Code Playgroud)
但它远非像原来的运行时:
> (when2 nil 2 3 4)
nil
> (when2 1 2 3 4)
(1 2 3 4)
> (when2 (< 1 2) 2 3 4)
((< 1 2) 2 3 4)
Run Code Online (Sandbox Code Playgroud)
我的错误来源是什么?
谢谢!
编辑:在siehe-falz的回复之后,我试过了
(macroexpand '(when2 1 2 3 4))
Run Code Online (Sandbox Code Playgroud)
这给了
(if 1 (progn '(2 3 4)) nil)
Run Code Online (Sandbox Code Playgroud)
并让我意识到我不应该在预测之后得到那个引用和那些括号.
所以,我想出来了
(defmacro when2 (test &body args)
`(if ,test (progn ,args) nil) …
Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个函数来测试给定列表是否为循环,重新起始点是列表的开头.
预期成绩:
(setq liste '(a b c))
(rplacd (cddr liste) liste)
(circular liste) => t
(circular '(a b c a b c)) => nil
Run Code Online (Sandbox Code Playgroud)
因为我只是想测试任何后续项目是否为第一个'eq',我不想构建整个乌龟和野兔算法.
这是我的代码:
(defun circular (liste)
(let (beginningliste (car liste)))
(labels ( (circ2 (liste)
(cond
((atom liste) nil)
((eq (car liste) beginningliste) t)
(t (circ2 (cdr liste)))
) ) ) ) )
Run Code Online (Sandbox Code Playgroud)
编辑.我想我已经回答了我的第三个问题,因为我觉得我找到了一个更简单的方法.这会有用吗?
(defun circular (liste)
(cond
((atom liste) nil)
((eq (car liste) (cadr liste)) t)
(t (circular (rplacd liste (cddr liste)))) …
Run Code Online (Sandbox Code Playgroud) 我刚刚开始学习宏功能的概念。
我的老师要求我们创建一个宏函数,该函数的功能与incf
。
这是他给我们流行的一个例子
(defmacro mypop (nom)
(list 'prog1 (list 'car nom) (list 'setq nom (list 'cdr nom))) )
Run Code Online (Sandbox Code Playgroud)
这是我要变成宏的常规函数:
(defun iincf (elem &optional num )
(cond
((not num) (setq elem (+ 1 elem)))
(t (setq elem (+ num elem))) ) )
Run Code Online (Sandbox Code Playgroud)
这是我尝试将其转换为宏的尝试:
(defmacro myincf (elem &optional num )
(list 'cond
((list 'not num) (list 'setq elem (list '+ 1 elem)))
(t (list 'setq elem (list '+ num elem))) ) )
Run Code Online (Sandbox Code Playgroud)
但是,出现此错误,我不知道为什么:
*** - system::%expand-form: (list 'not num) should …
Run Code Online (Sandbox Code Playgroud) 我如何n*n
在Prolog中获得一个大小矩阵的对角线列表?
预期行为:
?- diagonal1([[1,3,2],[4,5,7],[6,8,9]],D1).
D1=[1,5,9]
?- diagonal2([[1,3,2],[4,5,7],[6,8,9]],D2).
D2=[2,5,6].
Run Code Online (Sandbox Code Playgroud)
(我使用内置函数很好.)
我试图在列表中找到原子的位置.
预期成绩:
(position-in-list 'a '(a b c d e))
给出0
(position-in-list 'b '(a b c d e))
给出1
(position-in-list 'Z '(a b c d e))
没有.
我有一个函数,当项目在列表中时,正确地给出位置:
(defun position-in-list (letter list)
(cond
((atom list) nil)
((eq (car list) letter) 0)
(t (+ 1 (position-in-list letter (cdr list))))))
Run Code Online (Sandbox Code Playgroud)
问题是,当项目不存在时它不返回nil,就好像它达到(atom list)
nil它会给出这个错误:*** - 1+: nil is not a number
当它取消堆栈时,它会尝试将值添加到nil
.
有没有办法调整这个功能(保持相同的结构),以便nil
当项目不在列表中时正确返回?
笔记:
我知道库中有一个position
函数,但我不想使用它.
我知道我的问题与此类似,但我上面提到的问题没有得到解决.
*编辑* 感谢大家的答案.虽然我没有必要的知识来理解你提到的所有建议,但它很有帮助.
我找到了另一个解决我问题的方法:
(defun position-in-list (letter liste)
(cond …
Run Code Online (Sandbox Code Playgroud) common-lisp ×5
lisp ×4
clisp ×1
file-io ×1
list ×1
macros ×1
position ×1
postgresql ×1
prolog ×1
recursion ×1
syntax ×1
syntax-error ×1
uuid ×1