小编Bil*_*osa的帖子

实现forkpty()的GNU Common Lisp包

我寻求实现的GNU Common Lisp包forkpty(); openpty()也将是一个很大的优势,login_tty()并将成为我可以忍受的奢侈品.(Duckduckgo,谷歌等没有任何帮助.)有这样的吗?哪里?

lisp common-lisp gnu-common-lisp

6
推荐指数
1
解决办法
298
查看次数

封闭如何引用自身?

假设我有一个像这样的裸骨样本的花园式闭包:

(let ((alpha 0) #| etc. |# )
  (lambda ()
    (incf alpha)
    #| more code here |#
    alpha))
Run Code Online (Sandbox Code Playgroud)

假设我(funcall)是该闭包的一个实例三次,并且在第三次执行的中间,这个闭包想要将它自己保存在某个地方(比如在哈希表中).然后我暂时没有(funcall)这个实例.然后我从哈希表中(funcall)再次检索此实例,并获得返回值4.

闭包中的函数如何引用自身,因此它可以将自己保存在该哈希表中?

编辑1:这是一个更详细的例子.我通过将闭包作为参数传递给自己来实现目标.但我希望闭包能够在不进行自我参数化的情况下完成所有这些操作.

 1 (defparameter *listeriosis* nil)
 2 (defparameter *a*
 3   (lambda ()
 4     (let ((count 0))
 5       (lambda (param1 param2 param3 self)
 6         (incf count)
 7         (when (= 3 count)
 8           (push self *listeriosis*)
 9           (push self *listeriosis*)
10           (push self *listeriosis*))
11         count))))
12 (let ((bee (funcall *a*)))
13   (princ (funcall bee 1 2 …
Run Code Online (Sandbox Code Playgroud)

lisp clisp common-lisp

5
推荐指数
2
解决办法
264
查看次数

如何编译使用cl-ppcre的clisp程序?

在Debian上,我正在尝试编译一个使用cl-ppcre软件包的CLISP程序.

一个示例,简化程序(我将其称为变体1)如下所示:

(asdf:load-system :cl-ppcre)

(princ (cl-ppcre:regex-replace-all "a" "abcde" "x"))
(terpri)
Run Code Online (Sandbox Code Playgroud)

当我运行它时::

clisp -q a3.lisp
Run Code Online (Sandbox Code Playgroud)

我懂了:

home:~/clisp/ercpp/compiling-program$ clisp -q a3.lisp
; Loading system definition from /usr/share/common-lisp/systems/cl-ppcre.asd into #<PACKAGE ASDF0>
; Registering #<SYSTEM :CL-PPCRE> as CL-PPCRE
; Registering #<SYSTEM :CL-PPCRE-TEST> as CL-PPCRE-TEST
0 errors, 0 warnings
xbcde
home:~/clisp/ercpp/compiling-program$ 
Run Code Online (Sandbox Code Playgroud)

但是当我试图编译它时:

clisp -q -c a3.lisp
Run Code Online (Sandbox Code Playgroud)

我懂了:

home:~/clisp/ercpp/compiling-program$ clisp -q -c a3.lisp
;; Compiling file /u/home/clisp/ercpp/compiling-program/a3.lisp ...
*** - READ from
       #<INPUT BUFFERED FILE-STREAM CHARACTER
         #P"/u/home/clisp/ercpp/compiling-program/a3.lisp" @3>
      : there is no package with name "CL-PPCRE" …
Run Code Online (Sandbox Code Playgroud)

lisp clisp common-lisp

5
推荐指数
1
解决办法
960
查看次数

确定超类型路径

给定内容为1的变量,我知道它是至少五种类型的成员:

 1 (let* ((fred 1))
 2   (princ (typep fred 'bit)) (terpri)
 3   (princ (typep fred 'integer)) (terpri)
 4   (princ (typep fred 'fixnum)) (terpri)
 5   (princ (typep fred 'rational)) (terpri)
 6   (princ (typep fred t)) (terpri))
T
T
T
T
T
Run Code Online (Sandbox Code Playgroud)

这里有两个问题.

  1. 给定具有任意内容的变量,如何确定其超类型路径?

  2. 我在哪里可以在文档中找到答案?

lisp clisp common-lisp gnu-common-lisp

5
推荐指数
1
解决办法
127
查看次数

python:获取操作系统的 argv[0],而不是 sys.argv[0]

(这个问题是在这里问的,但答案是特定于 Linux 的;我在 FreeBSD 和 NetBSD 系统上运行,这些系统(编辑:通常)没有/proc。)

Python 似乎很笨拙argv[0],因此您不会像 C 程序那样获得传递给进程的内容。公平地说,sh、bash 和 Perl 也好不到哪里去。有什么办法可以解决这个问题,这样我的 Python 程序就可以获得原始值吗?我在这个 FreeBSD 系统上有管理权限,可以做一些事情,比如更改每个人的默认 PATH 环境变量以指向包含 python2 和 python3 的目录之前的某个其他目录,但我无法控制创建/proc. 我有一个脚本来说明这个问题。首先,脚本的输出:

the C child program gets it right: arbitrary-arg0 arbitrary-arg1
the python2 program dumbs it down: ['./something2.py', 'arbitrary-arg1']
the python3 program dumbs it down: ['./something3.py', 'arbitrary-arg1']
the sh script       dumbs it down: ./shscript.sh arbitrary-arg1
the bash script     dumbs it down: ./bashscript.sh arbitrary-arg1
the perl script drops …
Run Code Online (Sandbox Code Playgroud)

python

5
推荐指数
1
解决办法
235
查看次数

GNU Common Lisp的详细信息(类型)

如果在REPL我输入:

(type-of (make-array 5))
Run Code Online (Sandbox Code Playgroud)

然后我得到了答复:

(SIMPLE-VECTOR 5)
Run Code Online (Sandbox Code Playgroud)

很公平.所以如果在REPL我进入:

(type-of (make-array (list 5 3 2)))
Run Code Online (Sandbox Code Playgroud)

然后我得到了答复:

(SIMPLE-ARRAY T (5 3 2))
Run Code Online (Sandbox Code Playgroud)

我有两个问题.

  1. T告诉我什么?如果NIL相反,那会告诉我什么?
  2. 我在哪里可以自己找到这个答案?我没能在(例如)Lisp HyperSpec中找到答案.

lisp clisp common-lisp gnu-common-lisp

4
推荐指数
1
解决办法
211
查看次数

我如何要求Lisp编译器忽略(标签种类)函数?

我盯着斯蒂尔的Common Lisp the Language,直到我脸色苍白,仍然有这个问题.如果我编译:

(defun x ()
  (labels ((y ()))
    5))
(princ (x))
(terpri)
Run Code Online (Sandbox Code Playgroud)

有时候是这样的:

home:~/clisp/experiments$ clisp -c -q x.lisp
;; Compiling file /u/home/clisp/experiments/x.lisp ...
WARNING in lines 1..3 :
function X-Y is not used.
Misspelled or missing IGNORE declaration?
;; Wrote file /u/home/clisp/experiments/x.fas
0 errors, 1 warning
home:~/clisp/experiments$ 
Run Code Online (Sandbox Code Playgroud)

很公平.那么我如何要求编译器忽略函数y?我试过这个:

(defun x ()
  (labels (#+ignore(y ()))
    5))
(princ (x))
(terpri)
Run Code Online (Sandbox Code Playgroud)

它工作:

home:~/clisp/experiments$ clisp -c -q y.lisp
;; Compiling file /u/home/clisp/experiments/y.lisp ...
;; Wrote file /u/home/clisp/experiments/y.fas
0 errors, 0 …
Run Code Online (Sandbox Code Playgroud)

lisp clisp common-lisp

4
推荐指数
1
解决办法
1344
查看次数

以root身份运行的Perl脚本(通用)

我希望能够以root身份在我的系统上运行某些Perl脚本,即使调用它们的"用户"没有以root身份运行.

对于每个脚本,我可以编写一个C包装器,为该包装器设置setuid root; 包装器会将UID更改为0,然后调用Perl脚本,该脚本本身不会设置setuid位.这避免了在尝试运行setuid根脚本时出现的不幸障碍.

但我不想为每个脚本编写一个C包装器.我只想要一个C包装器来完成整个系统的工作.我也不希望任何脚本都能使用这个C包装器; C包装器本身应该能够检查Perl脚本的某些特定特性,以查看是否可以将UID更改为root.

我还没有看到任何解决此问题的其他Stack Overflow问题.

我知道风险,我拥有这个系统,而且我不想让任何东西随意地照顾我.

perl setuid

3
推荐指数
1
解决办法
603
查看次数

访问 sbcl errno 字符串

在 sbcl 中,当打开一个不存在的文件时,我可以像在这里一样处理错误:

(require "SB-POSIX")
(let* (fd)
   (handler-case
       (setf fd (sb-posix:open "w" sb-posix:o-rdonly))
     (sb-posix:syscall-error (c)
       (princ "error ")
       (princ (sb-posix:syscall-errno c))
       (princ " during ")
       (princ (sb-posix:syscall-name c))
       (terpri))))
error 2 during OPEN-WITHOUT-MODE
Run Code Online (Sandbox Code Playgroud)

如果我没有发现错误,结果的顶部看起来像这样:

 (require "SB-POSIX")
 (let* (fd)
   (setf fd (sb-posix:open "w" sb-posix:o-rdonly)))
Unhandled SB-POSIX:SYSCALL-ERROR:
  Error in SB-POSIX::OPEN-WITHOUT-MODE: No such file or directory (2)

Backtrace for: #<SB-THREAD:THREAD "main thread" RUNNING {1001976AB3}>
Run Code Online (Sandbox Code Playgroud)

看到那里“没有这样的文件或目录”吗?有没有办法让我的代码可以访问该字符串,以便我的错误处理程序可以说出比“错误 2”更不那么愚蠢的内容?

sbcl common-lisp

2
推荐指数
1
解决办法
60
查看次数

错误的Perl语法会产生错误的错误消息

以下(很多精简版)代码有一个明显的错误.

#!/usr/bin/env perl

use strict;
use warnings FATAL=>"all";

my $err_phyle;
my $verb;

sub do_measure
{
  print($error_phyle "xxx");

}

sub dye
{
}

dye "invalid verb \"$verb\"";
Run Code Online (Sandbox Code Playgroud)

您希望错误消息是:

Global symbol "$error_phyle" requires explicit package name at example.pl line 11.
example.pl had compilation errors.
Run Code Online (Sandbox Code Playgroud)

......但实际上......

String found where operator expected at example.pl line 19, near "dye "invalid verb \"$verb\"""
Run Code Online (Sandbox Code Playgroud)

(请注意,第二条错误消息不会添加"example.pl有编译错误.".)

在实际程序中,错误消息指向一行数百行代码,远离实际错误.错误的错误消息指向错误的行,可能会导致尝试追踪语法错误.

通过dye用括号括起函数调用的参数,我可以在上面的程序中"修复"这个,我想我会完成程序并执行此操作.但这是Perl中的一个错误,或者(更可能是这种情况)我错过了关于Perl如何工作的内容吗?

perl syntax-error

1
推荐指数
1
解决办法
81
查看次数

lisp:defun不是符号的必需参数

当将遗留代码从clisp移植到sbcl时,我遇到了语法,这会引发此代码所说明的问题,该代码在clisp中运行时没有明显错误:

(defun foo ((alpha integer))
  (princ (type-of alpha))
  (princ " ")
  (prin1 alpha)
  (terpri))
(foo 3)
(foo 3.5)
(foo (list "beta" "gamma" "delta"))
;;; output follows ;;;
(INTEGER 0 281474976710655) 3
SINGLE-FLOAT 3.5
CONS ("beta" "gamma" "delta")
Run Code Online (Sandbox Code Playgroud)

显然integer在第一行纯粹作为评论装饰.

sbcl,遇到相同的定义#'foo,抱怨:

Required argument is not a symbol: (ALPHA INTEGER)
Run Code Online (Sandbox Code Playgroud)

这到底是什么意思integer?这两种行为中的哪一种(如果有的话)符合标准?

编辑:

有问题的遗留代码是某种(古老的)cl-lex,但不是这一种.

lisp clisp sbcl common-lisp

1
推荐指数
1
解决办法
430
查看次数

sbcl(和clisp):什么时候字符不是字符?(使用defconstant)

这个问题是关于sbcl - 或者我最初想的.问题:角色什么时候不是角色?请考虑以下代码:

(defconstant +asc-lf+    #\Newline)
(defconstant +asc-space+ #\Space)
(prin1 (type-of #\Newline  )) (terpri)
(prin1 (type-of #\Space    )) (terpri)
(prin1 (type-of +asc-lf+   )) (terpri)
(prin1 (type-of +asc-space+)) (terpri)
Run Code Online (Sandbox Code Playgroud)

正如所料,它产生:

STANDARD-CHAR
STANDARD-CHAR
STANDARD-CHAR
STANDARD-CHAR
Run Code Online (Sandbox Code Playgroud)

现在考虑这段代码:

(defun st (the-string)
  (string-trim '(#\Newline #\Space) the-string))
(princ "\"")
(princ (st "   abcdefgh   "))
(princ "\"")
(terpri)
Run Code Online (Sandbox Code Playgroud)

它产生:

"abcdefgh"
Run Code Online (Sandbox Code Playgroud)

但请考虑以下代码:

(defconstant +asc-lf+    #\Newline)
(defconstant +asc-space+ #\Space)
(defun st (the-string)
  (string-trim '(+asc-lf+ +asc-space+) the-string))
(princ "\"")
(princ (st "   abcdefgh   "))
(princ "\"")
(terpri)
Run Code Online (Sandbox Code Playgroud)

当您使用sbcl加载它时,它会为您提供:

While evaluating …
Run Code Online (Sandbox Code Playgroud)

lisp clisp sbcl common-lisp

0
推荐指数
2
解决办法
262
查看次数

标签 统计

common-lisp ×9

lisp ×8

clisp ×7

gnu-common-lisp ×3

sbcl ×3

perl ×2

python ×1

setuid ×1

syntax-error ×1