有没有人知道在Github仓库的主页上显示Travis CI等徽章的好方法,而不保留它们的版本控制?
我喜欢在首页上有徽章,但如果它们在README中提交,那么每个分支和分支都会引用来自master的徽章.在开发分支上没有徽章比不正确的徽章更好.
是否有一种简单的方法可以在Racket中将字符串截断为特定宽度?
例子:
(truncate "foobar" 3)
-> "foo"
(truncate "foobar" 6)
-> "foobar"
Run Code Online (Sandbox Code Playgroud)
我还想替换截断字符串的最后几个字符:
(truncate "foobar" 4 #:when-truncated "...")
-> "f..."
(truncate "foobar" 10 #:when-truncated "...")
-> "foobar"
Run Code Online (Sandbox Code Playgroud) 如果我有一个打印到的功能,(current-output-port)有没有一种简单的方法来运行该函数而不打印到输出端口?
以前,我用作/dev/null输出目标:
(with-output-to-file "/dev/null" #:exists 'append
(lambda () (displayln "hello world")))
Run Code Online (Sandbox Code Playgroud)
这很容易,但取决于平台.我有时会忘记#:exists国旗.
一般问题:
我可以racket从正在运行的Racket脚本中调用当前的可执行文件吗?
基本上,我想(system "racket ...")在(find-executable-path "racket")不返回我正在使用的Racket可执行文件的路径的情况下替换.
语境:
我真正想要的是尝试编译一些表达式并断言它们会引发编译错误.这是用于单元测试.
当我尝试通过 raco 安装软件包时,收到一条奇怪的错误消息:
raco setup: directory: #<path:/Users/ben/code/racket/benchmark/tr-pfds/pfds> does not exist for collection: "pfds"
Run Code Online (Sandbox Code Playgroud)
更奇怪的是,运行raco pkg show并没有显示关于这个“pfds”集合的任何信息:
Installation-wide:
Package Checksum Source
main-distribution f07e2d4bf2708c1085be38eca18aa9eb6755e547 (catalog main-distribution)
racket-lib 41c7b3221006758c5a840a18dcc0d265632f14c2 (catalog racket-lib)
[178 auto-installed packages not shown]
User-specific for installation "6.1":
Package Checksum Source
benchmark 1237b50804bb42bd242ba7b3eb6e2b98794b40ee (catalog benchmark)
feature-profile 109e89701839a6d2fed9d1713aef8d21cc8b54d4 (catalog feature-profile)
quickcheck 1afac87825c5da8b35b327f5df3f1f9e1bf3cb9d (catalog quickcheck)
rackunit-chk 9c6e9c346c0e83bd3bb8dd16e321a2fa3e02b42e (catalog rackunit-chk)
Run Code Online (Sandbox Code Playgroud)
我尝试的另一件事是删除“pfds”集合,但这也不顺利:
raco6.1 pkg remove pfds
Removing pfds
raco6.1 pkg remove: package not currently installed
package: pfds
current scope: user
Run Code Online (Sandbox Code Playgroud)
但回想起来,这个错误对我来说很有意义,因为/Users/ben/code/racket/benchmark/tr-pfds/pfds我的机器上不存在该目录。我几周前删除了它。 …
scala 2.11宏可以强制其参数的宏扩展吗?
这是我的用例:我从文档开始使用printf宏,然后创建自己的宏来连接字符串.
def mconcat(s1: String, s2: String, s3: String): String = macro mconcat_impl
def mconcat_impl(c: Context)(s1: c.Expr[String], s2: c.Expr[String], s3: c.Expr[String]): c.Expr[String] = {
import c.universe._
c.Expr[String](q"""$s1.concat($s2.concat($s3))""")
}
Run Code Online (Sandbox Code Playgroud)
我希望结合这两个宏,
mprintf(mconcat("what", "a", "burger"))
Run Code Online (Sandbox Code Playgroud)
但宏扩展中出现匹配错误.
编辑
感谢Travis Brown指出mconcat不会扩展为字符串文字.对于那个很抱歉!但是如果我们简化以下内容仍然存在问题mconcat:
c.Expr[String](q"""$s1""")
Run Code Online (Sandbox Code Playgroud)
或者
s1
Run Code Online (Sandbox Code Playgroud)
甚至到
c.Expr[String](Literal(Constant("what")))
Run Code Online (Sandbox Code Playgroud)
这三个都给出了相同的错误消息:
Test.scala:8: error: exception during macro expansion:
scala.MatchError: ("what": String) (of class scala.reflect.internal.Trees$Typed)
at Printf$.printf_impl(Printf.scala:23)
mprintf(mconcat("what", "a", "burger"))
^
one error found
Run Code Online (Sandbox Code Playgroud) 我正在尝试用于defproc格式化函数定义(而不是记录库)。下面的代码获得了正确的格式,但是当我运行 Scribble 时会向控制台打印一个丑陋的警告:
#lang scribble/manual
@require[(for-label racket/contract)]
@defproc[(f [x integer?]) integer?]{
The best @racket[f].
}
Run Code Online (Sandbox Code Playgroud)
运行scribble --html example.scrbl打印:
example.scrbl:4:10: WARNING: no declared exporting libraries for definition
in: f
Run Code Online (Sandbox Code Playgroud)
有什么方法可以defproc用于格式化,并删除错误消息?
换句话说,有没有办法在看起来不像的表单上触发宏扩展(MACRO arg* ...).
举一个假设的例子:
(defmacro my-var
(do (printf "Using my-var!\n") 42))
(+ my-var 1) ;; Should print & return 43
Run Code Online (Sandbox Code Playgroud)
我真正想做的是调用macroexpand带有自由变量的术语.我希望这些自由变量在宏扩展期间应具有特殊含义,但之后应该回到"正常".
有没有办法检测宏是否在模式匹配中扩展?
这是我想写的一个示例宏,但它在一个内部失败match-define:
#lang racket/base
(require racket/match (for-syntax racket/base syntax/parse))
(struct point (x y))
(define-syntax (friendly-point stx)
(syntax-parse stx
[(_ arg* ...)
#'(begin (printf "Now making a point\n") (point arg* ...))]
[_ #'(begin (printf "Hello point\n") point)]))
(define p (friendly-point 1 2))
;; Prints "Now making a point"
(match-define (friendly-point x y) p)
;; ERROR
Run Code Online (Sandbox Code Playgroud) 有没有办法控制结构的打印方式?
例如,如果我有一个包含图像的透明结构:
(struct photo (label image-data) #:transparent)
Run Code Online (Sandbox Code Playgroud)
但我不想打印这个image-data领域.
每次我在 PLT redex 中定义一种语言时,我都需要手动定义一个(避免捕获)替换函数。例如,这个模型没有完成,因为subst没有定义:
#lang racket/base
(require redex/reduction-semantics)
(define-language ?
[V ::= x (? x M)]
[M ::= (M M) V]
[C ::= hole (V C) (C M)]
[x ::= variable-not-otherwise-mentioned])
(define -->?
(reduction-relation ?
[--> (in-hole C ((? x M) V))
(in-hole C (subst M x V))]))
Run Code Online (Sandbox Code Playgroud)
但定义subst是显而易见的。PLT redex 可以自动处理替换吗?
我有一些文件以这样的方式开头:
#lang racket/base
(require "my-library.rkt")
Run Code Online (Sandbox Code Playgroud)
如果我能用以下内容启动文件,我会非常高兴:
#lang my-library
Run Code Online (Sandbox Code Playgroud)
是否可以使用库作为#lang?我需要做些什么改变my-library.rkt?
有没有一种简单的方法来测量 Racket 程序的内存使用情况?我正在尝试并行运行许多程序,并且我想确保每个程序都有足够的内存。