给定一个没有修饰符的键的键代码,我想产生按shift +键的结果.示例:对于标准美国键盘,<shift> + <period>给出>.
相关的功能是UCKeytranslate,但我需要一些帮助来获得正确的细节.下面的代码片段是一个完整的程序,可以在XCode中运行.该程序的目的是给出<period>来产生字符>.
该计划的结果是:
Keyboard: <TSMInputSource 0x10051a930> KB Layout: U.S. (id=0)
Layout: 0x0000000102802000
Status: -50
UnicodeString: 97
String: a
Done
Program ended with exit code: 0
Run Code Online (Sandbox Code Playgroud)
获得布局的部分似乎正在工作,但状态代码显示出现了问题.但是什么?
import Foundation
import Cocoa
import Carbon
import AppKit
// The current text input source (read keyboard) has a layout in which
// we can lookup how key-codes are resolved.
// Get the a reference keyboard using the current layout.
var unmanagedKeyboard = TISCopyCurrentKeyboardLayoutInputSource()
var keyboard = unmanagedKeyboard.takeUnretainedValue() as TISInputSource
print("Keyboard: ") …Run Code Online (Sandbox Code Playgroud) euler.rkt我当前的工作目录中有一个文件.如何将其作为模块加载?
-> (require euler)
; readline-input:20:9: euler: standard-module-name-resolver: collection not
; found: "euler" in any of: (#<path:/home/ben/.racket/5.2.1/collects>
; #<path:/home/ben/racket/collects>) in: euler [,bt for context]
->
Run Code Online (Sandbox Code Playgroud)
我应该添加我的目录来收集吗?如果是这样,那么正确的方法是什么?
首先,据我所知,变量标识符在常见的lisp中称为符号.
我注意到,在像C这样的语言中,变量标识符只能是alphanumberics和underscores,Common Lisp允许使用更多的字符,如"*"和(至少是scheme)"?"
所以,我想知道的是:Common Lisp允许在符号中使用的完整字符集是什么(如果我错了,可以使用变量标识符)?对于Scheme来说是一样的吗?
另外,函数名称的字符集是不同的?
我一直在谷歌搜索,查看CLHS,以及Practical Common Lisp,对于我的生活,有些事情一定是错的,因为我似乎无法找到答案.
我正在尝试关注如何使用2D绘图的球拍文档.不幸的是,我似乎无法让它工作(可能是简单的事情)
我的代码是:
#lang racket
(require plot)
(plot (function sin (-pi) pi #:label "y = sin(x)"))
Run Code Online (Sandbox Code Playgroud)
而错误是:
compile: unbound identifier in module in: function
Run Code Online (Sandbox Code Playgroud)
我是一个球拍/ lisp新手,所以如果很明显,我只是没有意识到.我也试过插入(require racket/gui/base),(plot-new-window? #t)但那些似乎也没有做到这一点.
我在Ubuntu 12.04上使用racket v5.1.3.我没有使用Dr. Racket.
这是男人或男孩测试计划代码:
(define (A k x1 x2 x3 x4 x5)
(define (B)
(set! k (- k 1))
(A k B x1 x2 x3 x4))
(if (<= k 0)
(+ (x4) (x5))
(B)))
Run Code Online (Sandbox Code Playgroud)
为了简化评估过程,我将其重写为:
(define (A k x1 x2)
(define (B)
(set! k (+ k -1))
(A k B x1))
(if (> 1 k)
(x2)
(B)))
Run Code Online (Sandbox Code Playgroud)
我无法理解为什么(A 2 (lambda () 1) (lambda () -1))返回1.
任何人都可以解释Scheme解释器如何逐步评估此表达式.如果你可以附上环境图,那就更好了:)
的类型注释应该是什么foo?
(define (foo)
(println "hello"))
Run Code Online (Sandbox Code Playgroud)
我尝试了这些,但没有一个起作用:
(: foo (-> () ()))
(: foo (-> Void Void))
Run Code Online (Sandbox Code Playgroud) 对于新的类似方案、依赖类型的语言“Pie”,我购买了该语言的姊妹书:The Little Typer ( http://thelittletyper.com/ )
我试图使用 DrRacket 来遵循代码,但是当我在书中键入代码时出现错误。
(cons 'ratatouille 'baguette)
Run Code Online (Sandbox Code Playgroud)
我收到此错误:“无法确定类型”
由于这两个符号都是原子,那么对 cons 的调用不应该起作用吗?
此外,“+”函数是未定义的,即使对于数字也是如此。Pie有没有可以导入的前奏来提供这样的基本东西。
我正在使用racket并需要背景 bitmap图像制作游戏。但是我选择的图像太大了。如何更改大小?我拥有的:
(bitmap/url "http://www.example.com/")
Run Code Online (Sandbox Code Playgroud) 假设我在Scheme中创建了一个向量/数组:
(let* ((x #(1 2 3)))
(list-ref x 0)) ; returns error
Run Code Online (Sandbox Code Playgroud)
我可以在list-ref的位置使用什么语法或函数1?
编辑:我正在使用Script-Fu和GIMP 2.8,array-ref这似乎不起作用.
如何可视化任意树?
例如:
(define T1 '(and (or x1 x2)(or x3 x4 x5)))
或者使用以下命令生成:
(define functions '(not if and or))
(define terminals '(A0 A1 A2 D0 D1))
(define functions&terminals (append terminals functions ))
(define (pick-one list)
(list-ref list (random (length list))))
(define arities '((if . 3)(and . 2)(or . 2)(not . 1)))
(define (terminal? symbol)
(find (lambda (x)(eq? x symbol)) terminals))
(define (function? symbol)
(find (lambda (x)(eq? x symbol)) functions))
(define (arity non-terminal)
(let ((arity (find (lambda (x)(eq? non-terminal (car x))) arities))) …Run Code Online (Sandbox Code Playgroud) racket ×6
scheme ×5
lisp ×2
arrays ×1
cocoa ×1
common-lisp ×1
htdp ×1
image ×1
interpreter ×1
lambda ×1
macos ×1
objective-c ×1
pict ×1
pie-lang ×1
swift ×1
tree ×1
typed-racket ×1
url ×1
vector ×1