scheme

Cartesian product in Scheme

纵然是瞬间 提交于 2019-12-05 09:08:46
I've been trying to do a function that returns the Cartesian Product of n sets,in Dr Scheme,the sets are given as a list of lists,I've been stuck at this all day,I would like a few guidelines as where to start. ----LATER EDIT ----- Here is the solution I came up with,I'm sure that it's not by far the most efficent or neat but I'm only studing Scheme for 3 weeks so be easy on me. Here's a concise implementation that is also designed to minimize the size of the resulting structure in memory, by sharing the tails of the component lists. It uses SRFI-1. (define (cartesian-product . lists) (fold

Does Scheme/Racket have an enumeration operation?

痴心易碎 提交于 2019-12-05 08:50:03
Does Scheme/Racket have an enumeration notation equivalent to the [a..b] notation in Haskell? In Haskell, [1..5] evaluates to a list [1,2,3,4,5]. (for/list ([i (in-range 1 6)]) i) (sequence->list (in-range 1 6)) (require srfi/1) (iota 5 1) (for/list ([i 5]) (+ 1 i)) (build-list 5 add1) Also, (in-range 1 6) (which is a sequence ) by itself is useful in many contexts. 来源: https://stackoverflow.com/questions/7144248/does-scheme-racket-have-an-enumeration-operation

How can I tell if a list has a third item?

倖福魔咒の 提交于 2019-12-05 08:43:20
I have a function that takes a list that either has two or three elements. ;; expecting either ((a b c) d) or ((a b c) d e) (define (has-third-item ls) (if (null? (caddr ls)) false true) ) But this code fails with mcar: expects argument of type <mutable-pair>; given () on the (null? (caddr ls)) expression. I also tried (eq? '() (caddr ls)) but it didn't work either. How do I tell if there's a third item or not? You don't want caddr, you want (if (null? (cddr ls)) ... Or just use length to find the length of the list, and compare it to the value you're interested in. The '() that terminates a

Racket: Identifying tail recursion?

浪尽此生 提交于 2019-12-05 08:32:39
I wrote two different functions in racket to determine whether a list of numbers is ascending: (define (ascending list) (if (<= (length list) 1) #t (and (< (car list) (car (cdr list))) (ascending (cdr list))))) (define (ascending-tail list) (ascending-tail-helper #t list)) (define (ascending-tail-helper prevBool rest) (if (<= (length rest) 1) prevBool (ascending-tail-helper (and prevBool (< (car rest) (car (cdr rest)))) (cdr rest)))) I had the hardest time determining whether or not the first ascending was tail recursive, so I rewrote it using what I believe to be tail recursion. The reason

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

非 Y 不嫁゛ 提交于 2019-12-05 08:17:15
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 answer to an earlier question of mine , I have tried to use a music function , but there is no way I can

drf源码分析系列---版本控制

左心房为你撑大大i 提交于 2019-12-05 07:30:52
版本的使用 第一步:写路由url(r'^api/(P<version>\w+)/user/$',views.UserView.as_view()), 第二步:写模块导入from rest_framework.versioning import URLPathVersioning 第三步:写视图 可不写 request.version获取版本号 class UserView(APIView): # DEFAULT_VERSIONING_CLASS在APIView中默认配置 def get(self,request,*args,**kwargs): print(request.version) return Response('....') 第四步:写settings配置: REST_FRAMEWORK = { "DEFAULT_VERSIONING_CLASS": "rest_framework.versioning.URLPathVersioning", #配置全局的版本信息 "ALLOWED_VERSIONS":['v1','v2'] #配置允许版本号范围 } 版本的源码分析 执行流程 1.请求进来执行dispatch方法中的initialize_request方法 def initialize_request(self, request, *args, **kwargs):

Multidimensional vectors in Scheme?

一世执手 提交于 2019-12-05 07:19:22
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 probably do it is to just iterate through each element of the currently highest dimension of the vector to

Is there any difference between closure in Scheme and usual closure in other languages?

橙三吉。 提交于 2019-12-05 06:51:29
I'm studying SICP right now. And I found the definition of closure in SICP is (maybe) different from closure definition in other languages. Here's what SICP says: The ability to create pairs whose elements are pairs is the essence of list structure's importance as a representational tool. We refer to this ability as the closure property of cons. In general, an operation for combining data objects satisfies the closure property if the results of combining things with that operation can themselves be combined using the same operation. Here closure is more close to closure in Mathematics I think,

Variable in a function

白昼怎懂夜的黑 提交于 2019-12-05 06:29:40
I have see the following code... The first call of (next-num) returns 1 , and the second returns 2 . (define next-num (let ((num 0)) (lambda () (set! num (+ num 1)) num))) (next-num) ; 1 (next-num) ; 2 What I can not understand is... num is created by let inside next-num , it is kind of a local variable... How does scheme know that each time next-num is called, the value of num is not erased by let ((num 0)) ; How does scheme know that it is always the same num that we modify whenever next-num is called? It seems that num is both local and static... How can we define a local variable, but not

iOS 马甲包制作(Config 配置)

亡梦爱人 提交于 2019-12-05 06:09:38
Project→Info→Configuration→点击+(Debug和Release各添加一次) 执行pod install命令(没用pod略过) 新建Scheme 编辑Scheme(先选择 MaJiaTest_m 也就是马甲包 ) Run模式下更改 管理Scheme 右边的勾选 icon 和 启动页配置 复制文件夹 重命名就可以了 改icon配置 Targets→Build Settings,搜索asset或者Asset Catalog App Icon Set Name 配置App名称 Project→Build Settings →点击+ 选择 Add User-Defined Setting 名字为 CusomAppName info.plist中设置Bundle name为${CusomAppName} Identifier设置 Targets → Build Settings 搜索 Product Bundle Identifier 预编译宏设置 Targets → Build Settings 搜索 Preprocessor Macros 宏的使用代码 #ifdef MaJiaA NSLog( @"马甲" ); #else NSLog ( @"应用" ); #endif #ifdef DEBUG NSLog ( @"测试" ); #else NSLog( @"正式