小编pro*_*eek的帖子

如何检查变量是否设置为elisp/emacs中的内容?

假设我在.emacs文件中有以下行.

(setq-default default-directory "~/Desktop/mag")
Run Code Online (Sandbox Code Playgroud)

如何在elisp中检查`default-directory'的值?

添加

我问这个问题,因为我需要根据这个问题检查default-directory的值.

当我点击Cx Cf时,elisp代码应该更改默认目录,但我仍然得到〜/,而不是〜/ Desktop/mag.所以,我需要检查default-directory有什么值.

emacs elisp

9
推荐指数
3
解决办法
9424
查看次数

如何使用lisp(clisp)制作和使用库?

在C/C++中,我可以创建一个库,并在源代码中使用#include""将其设置为静态,或者在链接时使用-labc.如何在lisp中使用相同的功能?

作为目录A中util.lisp的一个例子.我定义了一个库函数hello.

(defpackage "UTIL"
  (:use "COMMON-LISP")
  (:nicknames "UT")
  (:export "HELLO"))

(in-package util)
(defun hello ()
  (format t "hello, world"))

并尝试从main函数使用此库函数.

(defun main ()
  (ut:hello))
(main)

我试过了

clisp main.lisp A/util.lisp 

但是,我得到了以下信息

*** - READ from #: there is no package with name "UT"
  • 使用库的#include""相当于什么?
  • 什么相当于-lutil加载库?clisp/sbcl使用该库的命令行是什么?
  • 对于defpackage,这是否等同于命名空间?

添加

我只需要加载库.

(load "./A/util.lisp")

(defun main ()
  (ut:hello))

(main)

并运行'clisp main.lisp'工作正常.

lisp clisp common-lisp

9
推荐指数
2
解决办法
3510
查看次数

使用Python/ElementTree在XML中插入元素的节点

当值小于5时,我需要遍历XML树以添加子元素.例如,可以将此XML修改为

<?xml version="1.0" encoding="UTF-8"?>
<A value="45">
    <B value="30">
        <C value="10"/>
        <C value ="20"/>
    </B>
    <B value="15">
        <C value = "5" />
        <C value = "10" />
    </B>
</A>
Run Code Online (Sandbox Code Playgroud)

这个XML.

<?xml version="1.0" encoding="UTF-8"?>
<A value="45">
    <B value="30">
        <C value="10"/>               
        <C value ="20"/>
    </B>
    <B value="15">
        <C value = "5"><D name="error"/></C>
        <C value = "10" />
    </B>
</A>
Run Code Online (Sandbox Code Playgroud)

我怎么能用Python的ElementTree做到这一点?

python xml elementtree

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

在ElementTree/Python中使用多个属性查找事件

我有以下XML.

<?xml version="1.0" encoding="UTF-8"?>
<testsuites tests="10" failures="0" disabled="0" errors="0" time="0.001" name="AllTests">
  <testsuite name="TestOne" tests="5" failures="0" disabled="0" errors="0" time="0.001">
    <testcase name="DefaultConstructor" status="run" time="0" classname="TestOne" />
    <testcase name="DefaultDestructor" status="run" time="0" classname="TestOne" />
    <testcase name="VHDL_EMIT_Passthrough" status="run" time="0" classname="TestOne" />
    <testcase name="VHDL_BUILD_Passthrough" status="run" time="0" classname="TestOne" />
    <testcase name="VHDL_SIMULATE_Passthrough" status="run" time="0.001" classname="TestOne" />
</testsuite>
</testsuites>
Run Code Online (Sandbox Code Playgroud)

问:我如何找到节点<testcase name="VHDL_BUILD_Passthrough" status="run" time="0" classname="TestOne" />?我找到了该函数tree.find(),但该函数的参数似乎是元素名称.

我需要根据属性找到节点:name = "VHDL_BUILD_Passthrough" AND classname="TestOne".

python xml elementtree

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

如何检查COM dll是否已注册C#?

我需要检查msdia100.dll是否在我正在运行的计算机系统上注册,以便使用该命令注册dll regsvr32.exe.我怎么能用C#做到这一点?

c# registry

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

使用Cocoa/objective-C从整数(年...第二)构建NSDate

我有年份,mont,...,整数类型的第二个,我需要从它们构建NSDate.我尝试了这段代码,但我得到了(null).

NSDateFormatter *tempFormatter = [[[NSDateFormatter alloc]init]autorelease];
[tempFormatter setDateFormat:@"yyyy-mm-dd hh:mm:ss"];
NSString* message = [NSString stringWithFormat:@"%04d-%02d-%02d %02d:%02d:%02d", year, month, day, hour, minute, second];
NSDate *day3 = [tempFormatter dateFromString:message];
Run Code Online (Sandbox Code Playgroud)

这段代码出了什么问题?

cocoa objective-c nsdate

9
推荐指数
2
解决办法
5041
查看次数

在C#中使用辅助功能修饰符继承属性

我试图继承接口,并将一些自动生成的set属性设置为private.这是一个例子.

public class MyClass
{
    public interface A 
    {
        int X {get; set;}
    }
    public interface B : A
    {
        int Y {get; set;}
    }

    public class C : A
    {
        public int X {get; private set;}
    }
Run Code Online (Sandbox Code Playgroud)

当我试图编译它.我收到了一个错误'MyClass.C' does not implement interface member 'MyClass.A.X.set'. 'MyClass.C.X.set' is not public..

我尝试private set;过iterface A,但我又得到了这个错误:'MyClass.A.X.set': accessibility modifiers may not be used on accessors in an interface.

C#中不允许使用此辅助功能修饰符吗?

c# inheritance properties

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

python中用户定义的类型检查:"type(A())是A"返回false

从这篇文章 - 用Python检查类型的规范方法是什么?,我可以使用此代码来检查对象o是字符串类型.

o = "str"; print type(o) is str --> True
Run Code Online (Sandbox Code Playgroud)

但是,使用用户定义的类型,type(a) is A似乎不起作用.

class A:
    def hello(self):
        print "A.hello"
a = A()

print type(a) is A # --> False
print type(a) == A # --> False
Run Code Online (Sandbox Code Playgroud)

为什么是这样?如何获得用户定义类型的正确类型检查?我在Mac OS X上使用python 2.7.

PS:这是一个出于好奇的问题,因为我从这本书中得到了这个例子,结果是真实的,但我得到了错误.我知道Duck打字是python中的首选方式.(/sf/answers/10790951/)

添加

罗德里戈的回答对我有用.使用'isinstance'并不能给我一个确切的类型,它只是测试一个对象是一个类的实例还是一个子类.

class C(A):
    def hello(self):
        print "C.hello"

a = A()
c = C()

print isinstance(a, A) --> True
print isinstance(c, A) --> True
print isinstance(a, C) --> False
print …
Run Code Online (Sandbox Code Playgroud)

python types

9
推荐指数
3
解决办法
2742
查看次数

为什么`-`(减号)不适用于操作员部分?

根据位置,Haskell中的部分应用程序得到了正确的答案.

Prelude> (/2) 10
5.0
Prelude> (2/) 10
0.2
Prelude> (+3) 10
13
Prelude> (3+) 10
13
Run Code Online (Sandbox Code Playgroud)

但是,对于 - 运算符,我得到了一个错误,(-3)因为Haskell(似乎)将其解释为值-3而不是部分应用程序.

Prelude> (-3) 10

<interactive>:4:1:
    Could not deduce (Num (a0 -> t))
      arising from the ambiguity check for ‘it’
    from the context (Num (a -> t), Num a)
      bound by the inferred type for ‘it’: (Num (a -> t), Num a) => t
      at <interactive>:4:1-7
    The type variable ‘a0’ is ambiguous
    When checking that ‘it’
      has the …
Run Code Online (Sandbox Code Playgroud)

haskell

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

仅使用SML/NJ打印打印输出

我正在尝试使用SML/NJ,我用它sml < source.sml来运行代码,但它打印出太多的信息.

例如,这是source.sml:

fun fac 0 = 1
  | fac n = n * fac (n - 1)
val r = fac 10 ;
print(Int.toString(r));
Run Code Online (Sandbox Code Playgroud)

这是输出:

Standard ML of New Jersey v110.77 [built: Tue Mar 10 07:03:24 2015]
- val fac = fn : int -> int
val r = 3628800 : int
[autoloading]
[library $SMLNJ-BASIS/basis.cm is stable]
[autoloading done]
3628800val it = () : unit
Run Code Online (Sandbox Code Playgroud)

来自标准ML中的抑制"val it"输出,如何禁用SMLNJ警告?,并且SMLNJ想要从每个print语句执行中删除"val it =():unit" …

ml sml smlnj

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