我希望John McCarthy还活着,但......
LISP可以解释和执行以S表达式形式编写的程序.因此,与机器语言一样,并且与大多数其他更高级语言不同,它可以用于生成用于进一步执行的程序.
我需要更多关于机器语言如何用于生成程序以及Lisp如何实现它的澄清?
lisp machine-language s-expression computer-science-theory racket
此示例取自tour.golang.org/#63
package main
import (
"fmt"
"time"
)
func say(s string) {
for i := 0; i < 5; i++ {
time.Sleep(100 * time.Millisecond)
fmt.Println(s)
}
}
func main() {
go say("world")
say("hello")
}
Run Code Online (Sandbox Code Playgroud)
hello
world
hello
world
hello
world
hello
world
hello
Run Code Online (Sandbox Code Playgroud)
为什么world只打印4时代而不是5?
编辑:答案可以引用golang规范:
程序执行从初始化主包然后调用main函数开始.当函数main返回时,程序退出.它不等待其他(非主要)goroutines完成.
来自字符串博客文章:
有些人认为Go字符串总是UTF-8,但它们不是:只有字符串文字是UTF-8.正如我们在上一节中所示,字符串值可以包含任意字节; 正如我们在本文中所展示的那样,字符串文字总是包含UTF-8文本,只要它们没有字节级转义即可.
总而言之,字符串可以包含任意字节,但是当从字符串文字构造时,这些字节(几乎总是)是UTF-8.
在功能继承模式中,Crockford superior通过以下方式引入了一种新方法:
Object.method('superior', function (name) {
var that = this,
method = that[name];
return function () {
return method.apply(that, arguments);
};
});
Run Code Online (Sandbox Code Playgroud)
在哪里method:
Function.prototype.method = function (name, func) {
this.prototype[name] = func;
return this;
};
Run Code Online (Sandbox Code Playgroud)
例:
var coolcat = function (spec) {
var that = cat(spec),
super_get_name = that.superior('get_name');
that.get_name = function (n) {
return 'like ' + super_get_name() + ' baby';
};
return that;
};
Run Code Online (Sandbox Code Playgroud)
我的问题是为什么不分配that.get_name给super_get_name ?
假设我有一个类型type T int,我想定义一个逻辑来操作这种类型.
我应该使用什么抽象和什么时候?
在该类型上定义方法:
func (T t) someLogic() {
// ...
}
Run Code Online (Sandbox Code Playgroud)定义一个功能:
func somelogic(T t) {
// ...
}
Run Code Online (Sandbox Code Playgroud)我正在阅读django 初学者书籍,\xc2\xa0 测试第 8 章中有关自定义用户模型的代码。目标是age通过对模型进行子类化来在 auth 用户模型中添加该字段AbstractUser。
首先我们创建CustomUser出models.py
from django.db import models\nfrom django.contrib.auth.models import AbstractUser\n\nclass CustomUser(AbstractUser):\n age = models.PositiveIntegerField(null=True, blank=True)\nRun Code Online (Sandbox Code Playgroud)\n\n然后创建CustomUserCreationFrom并CustomUserChangeFrom在forms.py:
from django import forms\nfrom django.contrib.auth.forms import UserCreationForm, UserChangeForm\n\nfrom .models import CustomUser\n\nclass CustomUserCreationFrom(UserCreationForm):\n class Meta(UserCreationForm.Meta):\n model = CustomUser\n fields = UserCreationForm.Meta.fields + (\'age\',)\n\nclass CustomUserChangeFrom(UserChangeForm):\n class Meta(UserChangeForm.Meta):\n model = CustomUser\n fields = UserChangeForm.Meta.fields\nRun Code Online (Sandbox Code Playgroud)\n\n最后,CustomUserAdmin在admin.py:
from …Run Code Online (Sandbox Code Playgroud) 我创建了一个OptionDialog没有任何按钮的项目,并JPanel在其中放入了一个用于MigLayout其布局的项目。那里面JPanel还有另一个。JPanel
这两个面板的外侧似乎都有边距。也许它是容器上的填充物。不管怎样,我想要一种摆脱它们的方法。
我怎样才能摆脱这些边距?在图片中,它们是 JPanel 周围的灰色和深橙色边框。

这是面板代码:
setBackground(new Color(239,209,59));
setLayout(new MigLayout("wrap 1"));
JLabel title = new JLabel("Enroll Today!", JLabel.CENTER);
Font f = title.getFont().deriveFont((float)36);
title.setFont(f);
add(title);
JPanel docsPanel = new JPanel();
docsPanel.setBorder(BorderFactory.createEmptyBorder());
docsPanel.setLayout(new MigLayout("wrap 1", "", "[grow,fill]"));
docsPanel.setBackground(new Color(255,235,115));
for (final Document d : docs){
JButton doc = new JButton("* "+d.getName());
doc.setFont(f.deriveFont((float)24));
doc.setBorder(null);
doc.setContentAreaFilled(false);
docsPanel.add(doc);
}
add(docsPanel);
Run Code Online (Sandbox Code Playgroud)
这是选项对话框代码:
DocumentPanel panel = new DocumentPanel(controller.getDocuments());
JOptionPane.showOptionDialog(null, panel, "Enroll now!", JOptionPane.DEFAULT_OPTION,
JOptionPane.PLAIN_MESSAGE, null, new Object[] {}, …Run Code Online (Sandbox Code Playgroud) 我已经symlink命名CURRENT为指向一个目录,可以说
CURRENT -> $HOME/local/java/jdk1.8.0
Run Code Online (Sandbox Code Playgroud)
我想将jdk1.8.0部分提取为字符串。
首先,我通过以下方式获取目录:
current_dir= $(readlink -f $CURRENT)
Run Code Online (Sandbox Code Playgroud)
然后,我尝试提取路径的最后一部分:
last_part= ${current_dir##*/}
Run Code Online (Sandbox Code Playgroud)
或者甚至当我尝试通过以下方式打印它时:
echo $current_dir
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
bash: /home/tarrsalah/local/java/jdk1.8.0: Is a directory
Run Code Online (Sandbox Code Playgroud)
如何将目录转换为字符串?
我刚刚从第17页开始阅读Java Concurrency in Practice
到目前为止,我们几乎可以互换地使用术语"线程安全类"和"线程安全程序".是一个完全由线程安全类构建的线程安全程序吗?不一定 - 完全由线程安全类组成的程序可能不是线程安全的,并且线程安全程序可能包含非线程安全的类.
我发现字节godoctype byte byte非常混乱,不应该是?type byte uint8
byte是uint8的别名,在所有方面都等同于uint8.按照惯例,它用于区分字节值和8位无符号整数值.type complex128
go ×4
java ×2
bash ×1
concurrency ×1
django ×1
django-admin ×1
goroutine ×1
javascript ×1
jpanel ×1
lisp ×1
miglayout ×1
python ×1
racket ×1
s-expression ×1
shell ×1
swing ×1
unicode ×1
unix ×1
utf-8 ×1