scheme

Multidimensional vectors in Scheme?

旧街凉风 提交于 2019-12-07 04:11:29
问题 I earlier asked a question about arrays in scheme (turns out they're called vectors but are basically otherwise the same as you'd expect). Is there an easy way to do multidimensional arrays vectors in PLT Scheme though? For my purposes I'd like to have a procedure called make-multid-vector or something. By the way if this doesn't already exist, I don't need a full code example of how to implement it. If I have to roll this myself I'd appreciate some general direction though. The way I'd

How to abbreviate 'note with the same note an octave higher, parenthesized' in Lilypond?

谁说我不能喝 提交于 2019-12-07 03:56:21
问题 Currently I write lilypond code that looks like this: \version "2.14.2" P = #parenthesize \relative c, { \clef bass <c \P c'> <e \P e'> <g \P g'>2 <c, \P c'>4 <d \P d'> <e \P e'>2 } where I repeatedly mean ' this note, together with the same note one octave higher, parenthesized'. I'd like a way to abbreviate this, so that I can write something like this: \version "2.14.2" poct = ... \relative c, { \clef bass \poct c \poct e \poct g2 \poct c,4 \poct d \poct e2 } As suggested in a helpful

Two-layer “Y-style” combinator. Is this common? Does this have an official name?

情到浓时终转凉″ 提交于 2019-12-07 03:56:15
问题 I've been looking into how languages that forbid use-before-def and don't have mutable cells (no set! or setq ) can nonetheless provide recursion. I of course ran across the (famous? infamous?) Y combinator and friends, e.g.: http://www.ece.uc.edu/~franco/C511/html/Scheme/ycomb.html http://okmij.org/ftp/Computation/fixed-point-combinators.html http://www.angelfire.com/tx4/cus/combinator/birds.html http://en.wikipedia.org/wiki/Fixed-point_combinator When I went to implement "letrec" semantics

Some Macro terms in Racket

不羁的心 提交于 2019-12-07 01:26:06
问题 I am confused by the terms for a long time, thinking it is good to ask out what exactly do they mean: A. syntax. B. syntax value. C. syntax object. D.s-expression E.datum (in syntax->datum) What's the difference between s-expression and symbol? What's the difference between s-expression and datum? What's the difference between (syntax, syntax values and syntax object) from s-expression? Code examples for explanation will be appreciated. 回答1: "Syntax" is a type for representing source code in

How to parse out base file name using Script-Fu

旧城冷巷雨未停 提交于 2019-12-07 01:05:44
问题 Using Gimp 2.6.6 for MAC OS X (under X11) as downloaded from gimp.org. I'm trying to automate a boring manual process with Script-Fu. I needed to parse the image file name to save off various layers as new files using a suffix on the original file name. My original attempts went like this but failed because (string-search ...) doesn't seem to be available under 2.6 (a change to the scripting engine?). (set! basefilename (substring filename 0 (string-search "." filename))) Then I tried to use

Which Scheme for Mac OS X Snow Leopard has the best support?

一个人想着一个人 提交于 2019-12-06 20:10:12
问题 There are a bunch of different Scheme interpreters available for the Mac: http://www.dmoz.org/Computers/Programming/Languages/Lisp/Scheme/Implementations/ Which one is generally supported the best? I'm also interested in 64-bit support and multi-core/processor support. 回答1: I don't know which ones are supported the best, but I've used Larceny, DrScheme and Bigloo. I believe that Larceny is widely believed to be the fastest open source scheme compiler available. It follows the unix tools based

Is there a possibility of multiple statements inside a conditional statement's body?

人盡茶涼 提交于 2019-12-06 17:09:02
问题 I'm primarily a C++ (thus an OO/imperative) programmer and I find it quite bizarre that you can only have one statement per evaluation in a conditional statement such as an if-statement in Scheme, a functional language. For example: (let ((arg1 0) (arg2 1)) (if (> arg1 arg2) arg1 arg2))) Erroneous example: (let ((arg1 0) (arg2 1)) (if (> arg1 arg2) (arg1 (display "cool")) (arg2 (display "not cool")))) gives me an error of a type "procedure application: expected procedure, given: 2; arguments

Generating list of 2-lists in Scheme

六眼飞鱼酱① 提交于 2019-12-06 16:31:48
(define cart-product (lambda (sos1 sos2) (if (null? sos1) '() (cons (cart-prod-sexpr (car sos1) sos2) (cart-product (cdr sos1) sos2))))) (define cart-prod-sexpr (lambda (s sos) (if (null? sos) '() (cons (list s (car sos)) (cart-prod-sexpr s (cdr sos)))))) Calling (cart-product '(q w) '(x y)) produces (((q x) (q y)) ((w x) (w y))) . How I can produce ((q x) (q y) (w x) (w y)) instead? Untested. Note that the append-list procedure I defined actually returns a list ending in sos2 . That is appropriate (and the right thing to do) here, but is not in general. (define cart-product (lambda (sos1 sos2

applicative-order/call-by-value and normal-order/call-by-name differences

巧了我就是萌 提交于 2019-12-06 16:03:57
Background I am learning the sicp according to an online course and got confused by its lecture notes. In the lecture notes, the applicative order seems to equal cbv and normal order to cbn. Confusion But the wiki points out that, beside evaluation orders(left to right, right to left, or simultaneous), there is a difference between the applicative order and cbv: Unlike call-by-value, applicative order evaluation reduces terms within a function body as much as possible before the function is applied. I don't understand what does it mean by reduced. Aren't applicative order and cbv both going to

Scheme procedure to compute the nth repeated application of a function?

你说的曾经没有我的故事 提交于 2019-12-06 14:52:00
Is anyone familiar with this? Write a procedure that takes as inputs a procedure that computes f and a positive integer n and returns the procedure that computes the nth repeated application of f. The procedure should be able to be used as follows: ((repeated square 2) 5) 625 I know that the following code I've created for the composition of functions will help make the solution simpler, but I'm not sure where to go from here: (define (compose f g) (lambda (x) (f (g x)))) Well, you probably want something like this, right? ((repeated square 3) 5) -> (square ((repeated square 2) 5)) -> (square