小编pro*_*eek的帖子

装饰器使用Python应用于类定义

与应用于函数的装饰器相比,理解应用于类的装饰器并不容易.

@foo
class Bar(object):
    def __init__(self, x):
        self.x = x
    def spam(self):
        statements
Run Code Online (Sandbox Code Playgroud)

装饰器对一个类的用例是什么?如何使用它?

python decorator

7
推荐指数
2
解决办法
865
查看次数

有没有办法在Mac OS上使用动态FFI支持编译CLISP?

我在Mac OS X 10.6.4上使用clisp 2.48(2009-07-28).我用'sudo port install clisp'下载了clisp.

安装快速lisp后,我安装了一些软件包,其中大多数都没问题.

但是,当我尝试安装"sqlite"时,我收到以下错误.

[1]> (ql:quickload "sqlite")
To load "sqlite":
  Load 1 ASDF system:
    sqlite
; Loading "sqlite"
[package cffi-sys]
*** - CFFI requires CLISP compiled with dynamic FFI support.

它说我的安装了mac port的clisp没有FFI支持.

有没有办法在Mac OS X上使用动态FFI支持编译CLISP?

clisp common-lisp macports quicklisp

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

有哪些工具可用于F#调试?

  • F#有gdb(或类似的)吗?
  • F#程序员通常使用哪些工具/程序来跟踪Mono中的F#代码?
  • Visual Studio 2010是否为F#提供了一些集成的调试工具?

debugging f#

7
推荐指数
2
解决办法
1408
查看次数

C#Emacs模式问题 - 缩进和构建

我安装了emacs C#模式.

.emacs文件如下

(require 'csharp-mode)
(setq auto-mode-alist
      (append '(("\\.cs$" . csharp-mode)) auto-mode-alist))
(defun my-csharp-mode-fn ()
  "function that runs when csharp-mode is initialized for a buffer."
  (setq default-tab-width 4)
)
(add-hook  'csharp-mode-hook 'my-csharp-mode-fn t)

它工作得很好,但我看到块({..})与我的意图一致.我的意思是,在某些情况下,我有这个.

private static int StringCompare(string x, string y)
{
  int result;
  if (x == null)
    {

    }
}
Run Code Online (Sandbox Code Playgroud)

当我期待这个

private static int StringCompare(string x, string y)
{
  int result;
  if (x == null)
  {

  }
}
Run Code Online (Sandbox Code Playgroud)

与此同时,我总是有2个代码缩进,但我希望它是4.

我的问题是

  • 如何在C#emacs模式下控制缩进?
  • 如何控制'{'和'}'与之前的代码具有相同的缩进.
  • C#模式是否提供编译以使用命令在编辑器中生成exe/dll文件?

我在Mac OS X/mono上使用emacs C#模式. …

c# emacs mono

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

用于XML字符串的Python pretty XML打印机

我使用python生成一个冗长而丑陋的XML字符串,我需要通过漂亮的打印机对其进行过滤以使其看起来更好.

我发现这篇文章适用于python漂亮的打印机,但是我必须将XML字符串写入要回读的文件以使用这些工具,如果可能的话我想避免使用这些工具.

什么python漂亮的工具可以在字符串上工作?

python xml pretty-print

7
推荐指数
2
解决办法
2万
查看次数

.NET堆栈与Windows堆栈

在Windows内部本书第5版有360页以下评论.

The stack size for the initial thread is taken from the image—there’s no way 
to specify another size.

据我所知,对于Windows操作系统,每个线程都有4K或16K(取决于系统)堆栈,并且大小是固定的.

那么.NET中的堆栈怎么样?

  • 堆栈有多大?
  • 堆栈的大小是固定的还是可变的?
  • 是否像Windows的情况一样为每个线程分配堆栈?

.net stack

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

凌乱的函数指针解释

我碰巧遇到了以下函数指针.

char (*(*x())[])();
Run Code Online (Sandbox Code Playgroud)

它看起来像以下格式的函数指针数组,但我看不出f - >(*x())的含义.如何解释这个凌乱的函数指针?

char (*f[])();
Run Code Online (Sandbox Code Playgroud)

添加

在John Bode的帮助下,我举了一个例子如下.

#include <stdio.h>

char foo()    { return 'a'; }
char bar()    { return 'b'; }
char blurga() { return 'c'; }
char bletch() { return 'd'; }

char (*gfunclist[])() = {foo, bar, blurga, bletch};

char (*(*x())[])()
{
  static char (*funclist[4])() = {foo, bar, blurga, bletch};
  return &funclist;
}

int main() 
{
  printf("%c\n",gfunclist[0]());

  char (*(*fs)[4])();
  fs = x();
  printf("%c\n",(*fs)[1]()); 
}
Run Code Online (Sandbox Code Playgroud)

我可以得到预期的结果.

smcho@prosseek temp2> ./a.out 
a
b

而且,您可以在此处找到更好的实施方案.

c c++ function-pointers

7
推荐指数
3
解决办法
553
查看次数

我可以将emacs(非窗口)中的长行打破到下一行吗?

在此输入图像描述

使用emacs(非窗口),当终端宽度很窄时,我会在行尾看到'$'标记.有没有办法打破下一行的长线而不是显示'$'标记?

添加

Mx自动填充模式适用于文本模式,但使用org-mode时,$ mark仍保留自动填充模式.

emacs split line

7
推荐指数
2
解决办法
7580
查看次数

F#将String Array转换为String

使用C#,我可以使用string.Join("", lines)将字符串数组转换为字符串.用F#做同样的事情我能做些什么?

添加

我需要从文件中读取行,执行一些操作,然后将所有行连接成一行.

当我运行此代码时

open System.IO
open String

let lines = 
  let re = System.Text.RegularExpressions.Regex(@"#(\d+)")
  [|for line in File.ReadAllLines("tclscript.do") ->
      re.Replace(line.Replace("{", "{{").Replace("}", "}}").Trim(), "$1", 1)|]

let concatenatedLine = String.Join("", lines)

File.WriteAllLines("tclscript.txt", concatenatedLine)
Run Code Online (Sandbox Code Playgroud)

我收到了这个错误

error FS0039: The value or constructor 'Join' is not defined
Run Code Online (Sandbox Code Playgroud)

我尝试使用此代码let concatenatedLine = lines |> String.concat ""来获取此错误

error FS0001: This expression was expected to have type
    string []    
but here has type
    string
Run Code Online (Sandbox Code Playgroud)

解

open System.IO
open System 

let lines = 
  let …
Run Code Online (Sandbox Code Playgroud)

string f#

7
推荐指数
2
解决办法
6721
查看次数

如何统一初始化unique_ptr的映射?

我有这个代码来初始化map到unique_ptr.

auto a = unique_ptr<A>(new A());
map<int, unique_ptr<A>> m;
m[1] = move(a);
Run Code Online (Sandbox Code Playgroud)

我可以使用统一初始化吗?我试过了

map<int, unique_ptr<A>> m {{1, unique_ptr<A>(new A())}};    
Run Code Online (Sandbox Code Playgroud)

但是我收到了一个错误.

错误消息的某些部分是

In instantiation of 'std::_Rb_tree_node<_Val>::_Rb_tree_node(_Args&& ...) [with _Args = {const std::pair<const int, std::unique_ptr<A, std::default_delete<A> > >&}; _Val = std::pair<const int, std::unique_ptr<A> >]': ... In file included from /opt/local/include/gcc48/c++/memory:81:0,
                 from smart_pointer_map.cpp:3: /opt/local/include/gcc48/c++/bits/unique_ptr.h:273:7: error: declared here
       unique_ptr(const unique_ptr&) = delete;

   ^
Run Code Online (Sandbox Code Playgroud)

c++ smart-pointers map uniform-initialization c++11

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