racket

DrRacket - Display all the values in a list that are above average

不羁的心 提交于 2020-02-26 02:14:05
问题 I'm creating a function that consumes a list of numbers and produces the elements in the list that are above average. Below is my code: (define (listlength list) (cond ((empty? list) 0) (else (+ 1 (listlength (rest list)))))) (define (listsum list) (cond [(empty? list) 0] [else (+ (first list) (listsum (rest list)))])) (define (average log) (/ (listsum log) (+ (listlength log) 1))) (define (average-filter log) (cons (cond [(> (first log) (average log)) (first log)] [else (average-filter (rest

Fast array access using Racket FFI

北城以北 提交于 2020-02-03 04:59:48
问题 I am trying to write OpenCV FFI in Racket and arrived at a point where arrays need to be manipulated efficiently. However, all my attempts to access arrays by using Racket FFI resulted in very inefficient code. Is there a way for fast access of C arrays using FFI? In Racket, this type of manipulation is reasonably fast, i.e.: (define a-vector (make-vector (* 640 480 3))) (time (let loop ([i (- (* 640 480 3) 1)]) (when (>= i 0) ;; invert each pixel channel-wise (vector-set! a-vector i (- 255

Fast array access using Racket FFI

无人久伴 提交于 2020-02-03 04:58:12
问题 I am trying to write OpenCV FFI in Racket and arrived at a point where arrays need to be manipulated efficiently. However, all my attempts to access arrays by using Racket FFI resulted in very inefficient code. Is there a way for fast access of C arrays using FFI? In Racket, this type of manipulation is reasonably fast, i.e.: (define a-vector (make-vector (* 640 480 3))) (time (let loop ([i (- (* 640 480 3) 1)]) (when (>= i 0) ;; invert each pixel channel-wise (vector-set! a-vector i (- 255

How to avoid loading cycle in Racket?

左心房为你撑大大i 提交于 2020-01-24 04:22:07
问题 I have quite simple set of .rkt sources and, say, "a.rkt" and "b.rkt" among them. I'd like to be able to write (require "a.rkt") in "b.rkt" and vice versa. Now I'm facing error about "loading cycle". Can I solve this issue with bare modules without adding units? Does Racket have anything similar to forward declaration so I could simple add missing signature instead of requiring? If both answers are "No", does someone know good and understandable tutorial on how to implement units with typed

How To Change Image Sizes in Racket

坚强是说给别人听的谎言 提交于 2020-01-23 11:18:51
问题 I am making a game using racket and need a background bitmap image. But the image I have selected is too big. How do I change the size? What I have: (bitmap/url "http://www.example.com/") 回答1: Import this package: (require htdp/image) And use the shrink procedures defined in that package. EDIT : As has been pointed out in the comments, 2htdp/image would be a better alternative: (require 2htdp/image) Take a look at the scale procedure. 来源: https://stackoverflow.com/questions/10318208/how-to

deep-reverse for scheme

╄→尐↘猪︶ㄣ 提交于 2020-01-17 08:44:50
问题 When entering the list of ((1 2) (3 4)), I want to reverse it, but not so it's ((3 4) (1 2)), which is what reverse does, so I'm trying to write a deep-reverse procedure: (define (deep-reverse l) (cond ((null? l) nil) (not (pair? (car l)) l) (else (append (deep-reverse (cdr l)) (list (car l)))))) but it just throws back ((1 2) (3 4)). What's wrong and how do I get this to work? 回答1: Try: (define (deep-reverse l) (map reverse l)) The above is the simplest possible answer; a real answer depends

How do I delete from a binary search tree in Lisp

南笙酒味 提交于 2020-01-15 18:32:28
问题 How can I delete a node from a BST? I need an algorithm to do that in Dr. Scheme. 回答1: You basically toss the BST you have now, and create a new one sans the element. You can do this by recursively descending the tree. If your item is less than the root datum, create a BST whose root and greater-than branch is copied from what you have now, but whose less-than branch is the result from a recursive call. It's very similar to how you add a node, but when you get to the one you were searching

Can't hide “Preferences” item in edit-menu

坚强是说给别人听的谎言 提交于 2020-01-15 09:32:11
问题 How do I hide "Preferences" item in this picture when "undo and redo" items are able to hide? I tried using (preferences:hide-dialog) but there was no difference in GUI. #lang racket/gui (require framework) (define menu-super-frame% (frame:standard-menus-mixin frame:basic%)) (define menu-frame% (class menu-super-frame% (inherit get-file-menu set-icon) ;hiding items in edit menu (define/override (edit-menu:create-undo?) #f) (define/override (edit-menu:create-redo?) #f) (super-new))) (define

Can't hide “Preferences” item in edit-menu

送分小仙女□ 提交于 2020-01-15 09:32:06
问题 How do I hide "Preferences" item in this picture when "undo and redo" items are able to hide? I tried using (preferences:hide-dialog) but there was no difference in GUI. #lang racket/gui (require framework) (define menu-super-frame% (frame:standard-menus-mixin frame:basic%)) (define menu-frame% (class menu-super-frame% (inherit get-file-menu set-icon) ;hiding items in edit menu (define/override (edit-menu:create-undo?) #f) (define/override (edit-menu:create-redo?) #f) (super-new))) (define

How ought I run the annotate function in gui-debugger/annotator on a datum?

China☆狼群 提交于 2020-01-15 03:08:19
问题 I am trying to learn how to use the DrRacket debugger's annotate function. My ultimate aim is to build a REPL that you can execute from within a closure and have access to everything that's in scope. (see my previous question on that topic and Greg Hendershott's well-researched answer) For the time being, I'm just trying to explore how the annotate function works. You can see my first exploratory attempt at using it, and the results, here. The error, which is happing inside of the annotator,