scheme

Using Lisp or Scheme for runtime configuration of Java programs

╄→尐↘猪︶ㄣ 提交于 2019-12-04 09:19:33
问题 I have now seen several projects ending at a point where the actual configuration depended on things only available at run-time. The typical way to configure a Java program is to read one or more property files according to some application specific rules and then take action depending on their values. At one point or another this breaks down and you need actual program logic in your configuration which then can be indicated with a flag and adding code to your application which then handles

Functional Programming - Implementing Scan (Prefix Sum) using Fold

自古美人都是妖i 提交于 2019-12-04 09:15:39
I've been teaching myself functional programming, and I'm currently writing different higher order functions using folds. I'm stuck implementing scan (also known as prefix sum). My map implementation using fold looks like: (define (map op sequence) (fold-right (lambda (x l) (cons (op x) l)) nil sequence)) And my shot at scan looks like: (define (scan sequence) (fold-left (lambda (x y) (append x (list (+ y (car (reverse x)))))) (list 0) sequence)) My observation being that the "x" is the resulting array so far, and "y" is the next element in the incoming list. This produces: (scan (list 1 4 8 3

How to show different content based on the path in Racket web servlets?

旧城冷巷雨未停 提交于 2019-12-04 09:09:36
I'm trying to follow the tutorial on the Racket guide on simple web apps, but can't get one, basic, basic thing. How can you have a servlet serve different content based on the request URL? Despite my scouring, even the huge blog example was one big file and everything handled with huge get query strings behind my back. How can I do anything based on URLs? Clojure's Noir framework puts this basic feature big up front on the home page ( defpage ) but how to do this with Racket? The URL is part of the request structure that the servlet receives as an argument. You can get the URL by calling

Django:RestFramework之-------版本控制

孤者浪人 提交于 2019-12-04 08:51:59
6.版本控制 从URL通过get传参获取版本。 6.1自定义版本控制 from rest_framework.views import APIView class ParamVersion(object): def determine_version(self,request,*args,**kwargs): version = request.query_params.get("version") return version class UserView(APIView): versioning_class = ParamVersion def get(self,request,*args,**kwargs): print(request.version) # version = request.query_params.get("version") # print(version) return HttpResponse("用户列表") 6.2内置类版本控制 #方式1: #settings.py配置 REST_FRAMEWORK = { #默认版本V1 "DEFAULT_VERSION":"V1", #允许版本V1,V2 "ALLOWED_VERSIONS":["V1","V2"], #URL上标识版本字段 "VERSION_PARAM":"version" } from

How to split list into evenly sized chunks in Racket (Scheme)?

删除回忆录丶 提交于 2019-12-04 08:38:59
Example: How to convert list: '(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) Into list of lists: '((0 1 2 3) (4 5 6 7) (8 9 10 11) (12 13 14 15)) Based on answers provided here so far, this is what I've come up with: First define function to take up to 'n' elements from beginning of the list: (define (take-up-to n xs) (define (iter xs n taken) (cond [(or (zero? n) (empty? xs)) (reverse taken)] [else (iter (cdr xs) (- n 1) (cons (car xs) taken))])) (iter xs n '())) Second is similar function for the rest of list: (define (drop-up-to n xs) (define (iter xs n taken) (cond [(or (zero? n) (empty? xs)) xs

Applying A List of Functions to a Number

爷,独闯天下 提交于 2019-12-04 08:26:34
I understand that functions in Scheme/Racket like map, foldr, and filter, can do wonderful things like apply a function to a list of elements. Is it possible to apply a list of functions to a single element? I would like to generate the values produced by each of the functions, then find their maximum. Thank you. For the first part, this procedure will apply a list of functions to a single argument, assuming that all the functions receive only one argument. A list with the results is returned (define (apply-function-list flist element) (map (lambda (f) (f element)) flist)) For the second part,

Lambda and the Environment Model

故事扮演 提交于 2019-12-04 07:59:29
I need help drawing the relevant portions of the environment model diagram when evaluating this code: Scheme>(define x 10) Scheme> ((lambda (x y) (+ (y 3) x)) 6 (lambda (w) (* x 9))) I need to make sure and write each lambda body next to the environment in which it is being evaluated. Okay I know that there is only one define so most of the work will be done by “anonymous” or “nameless” functions and these will still show up in various ways in the environment model diagram In addition to the answers already given, the 6.001 course at MIT has two very comprehensive lectures on the environment

Anonymous lambdas directly referring to themselves

早过忘川 提交于 2019-12-04 07:51:23
Does Scheme or do any dialects of scheme have a kind of "self" operator so that anonymous lambdas can recur on themselves without doing something like a Y-combinator or being named in a letrec etc. Something like: (lambda (n) (cond ((= n 0) 1) (else (* n (self (- n 1))))))) No. The trouble with the "current lambda" approach is that Scheme has many hidden lambdas. For example: All the let forms (including let* , letrec , and named let ) do (which expands to a named let ) delay , lazy , receive , etc. To require the programmer to know what the innermost lambda is would break encapsulation, in

Why is there no tail recursion optimization in Emacs lisp, not but like other scheme?

落花浮王杯 提交于 2019-12-04 07:48:25
Emacs lisp is a dialect of LISP and especially Scheme. Most of scheme interpreters do have a optimization of Tail Recursion, but emacs lisp doens't. I searched the reason in `info elisp' for a while, but I fail to find it. P.S. Yes, there is other iteration syntax in elisp like `while', but I still cannot find a good reason why they didn't implement tail recursion like other scheme interpreters. Emacs Lisp was created in the 1980's. The Lisp dialect that the Emacs author (Richard Stallman) was most familiar with at the time was MIT Maclisp, and Emacs Lisp is very similar to it. It used dynamic

Implicit currying in Scheme with syntax-rules?

耗尽温柔 提交于 2019-12-04 07:45:41
Jeffrey Meunier has an implicit Curry macro here , which uses defmacro. I was wondering if someone has ever written this with syntax-rules? There are a number of curry implementations for Scheme -- none can be as elegant as Haskell, since there functions are always unary functions, so everything can be curried. (But this can of course be implemented in a sufficiently powerful Scheme like Racket .) As for the macro that you've dug up -- it's a pretty bad one: not only does it use an unhygienic macro, it's also calling eval explicitly, and relies on an implementation of environments etc. But it