scheme

JQuery入门篇

瘦欲@ 提交于 2019-12-02 02:03:16
JQuery入门篇 jQuery选择器 “$”表示JQuery对象 根据ID查找 $(‘#var’)表示将一个id值为var的DOM节点封装成一个jQuery对象,DOM节点必须以“#”开头。 例如:有<div id="var "></div>存在,使用$(‘#var’)之后会将其封装成[<div id="var "></div>],但是如果不存在id=”var”,返回的jQuery对象是[],而不是一个null或undefined。 // 查找<div id="abc">: var div = $('#abc'); //获取id=”abc”的节点 根据class查找 1、只存在一个class样式: var a = $('.red'); // 所有节点包含`class="red"`都将返回 // 例如: // <div class="red">...</div> // <p class="green red">...</p> 根据Tag(标签)查找 var ps = $('p'); // 返回所有<p>节点 ps.length; // 数一数页面有多少个<p>节点 根据属性查找 var email = $('[name=email]'); // 找出 <??? name="email"> var passwordInput = $('[type=password]'); // 找出

Scheme number to list

孤街浪徒 提交于 2019-12-02 01:52:27
I need a subroutine for my program written in scheme that takes an integer, say 34109, and puts it into a list with elements 3, 4, 1, 0, 9. The integer can be any length. Does anyone have a trick for this? I've thought about using modulo for every place, but I don't think it should be that complicated. The simplest way I can think of, is by using arithmetic operations and a named let for implementing a tail-recursion: (define (number->list num) (let loop ((num num) (acc '())) (if (< num 10) (cons num acc) (loop (quotient num 10) (cons (remainder num 10) acc))))) Alternatively, you can solve

Scheme number to list

∥☆過路亽.° 提交于 2019-12-02 01:36:27
问题 I need a subroutine for my program written in scheme that takes an integer, say 34109, and puts it into a list with elements 3, 4, 1, 0, 9. The integer can be any length. Does anyone have a trick for this? I've thought about using modulo for every place, but I don't think it should be that complicated. 回答1: The simplest way I can think of, is by using arithmetic operations and a named let for implementing a tail-recursion: (define (number->list num) (let loop ((num num) (acc '())) (if (< num

R5RS Scheme input-output: How to write/append text to an output file?

谁说我不能喝 提交于 2019-12-02 01:33:08
What is a simple way to output text to file in a R5RS compliant version of Scheme? I use MIT's MEEP (which uses Scheme for scripting) and I want to output text to file. I have found the following other answers on Stackoverflow: File I/O operations - Scheme How to append to a file using Scheme Append string to existing textfile [sic] in IronScheme But, they weren't exactly what I was looking for. ansebbian0 The answers by Charlie Martin, Ben Rudgers, and Vijay Mathew were very helpful, but I would like to give an answer which is simple and easy to understand for new Schemers, like myself :) ;

Different nCurses behaviours with different terminals

南笙酒味 提交于 2019-12-02 01:29:06
I obtain two different behaviours using different terminals, this is my code: (use ncurses) (initscr) (curs_set 0) (noecho) (start_color) (define win (newwin 20 50 1 1)) (wclear win) (box win 0 0) (for-each (lambda (y) (for-each (lambda (x) (mvwaddch win y x #\. )) (iota 49))) (iota 19)) (wrefresh win) (wgetch win) (endwin) The code is written in Chicken Scheme but it's easily readable by anyone who knows nCurses. I think my problem doesn't concern the library because it's a simple wrapper which calls the C functions. However, I get the correct behaviour (a boxed window) if I use xterm, uxterm

A scheme procedure that returns a list of every other element

三世轮回 提交于 2019-12-02 01:19:40
问题 I'm having a bit of trouble implementing this program in Scheme, although I think I'm 90% of the way there. Unfortunately I need to be a little vague about it since this is a homework assignment. I want to (A B C D ) to return ( B D) . but i am getting an error that says The object (), passed as an argument to safe-car, is not a pair | " This is my code: (DEFINE (other_el lis) (COND (( NULL? lis ) '()) ((LIST? lis) (append (CADR lis) (other_el (CDR lis)))) (ELSE (show " USAGE: (other_el [LIST

List order after duplicate filtering

淺唱寂寞╮ 提交于 2019-12-02 01:03:21
I'm trying to teach myself functional language thinking and have written a procedure that takes a list and returns a list with duplicates filtered out. This works, but the output list is sorted in the order in which the last instance of each duplicate item is found in the input list. (define (inlist L n) (cond ((null? L) #f) ((= (car L) n) #t) (else (inlist (cdr L) n)) )) (define (uniquelist L) (cond ((null? L) '()) ((= 1 (length L)) L) ((inlist (cdr L) (car L)) (uniquelist (cdr L))) (else (cons (car L) (uniquelist (cdr L)))) )) So.. (uniquelist '(1 1 2 3)) => (1 2 3) ...but... (uniquelist '(1

Turn string into number in Racket

二次信任 提交于 2019-12-02 00:54:54
I used read to get a line from a file. The documentation said read returns any , so is it turning the line to a string? I have problems turning the string "1" to the number 1 , or "500.8232" into 500.8232 . I am also wondering if Racket can directly read numbers in from a file. Check out their documentation search , it's complete and accurate. Conversion functions usually have the form of foo->bar (which you can assume takes a foo and returns a bar constructed from it). You sound like you're looking for a function that takes a string and returns a number , and as it happens, string->number

Applying a symbol as a procedure

一曲冷凌霜 提交于 2019-12-02 00:52:21
Suppose I have a simple symbol: > '+ + Is there any way I can apply that symbol as a procedure: > ((do-something-with '+) 1 2) 3 So that '+ is evaluated to the procedure + ? I'm not 100% sure, but would: ((eval '+) 1 2) work? I'm not sure if you need to specify the environment, or even if that works - I'm a Scheme noob. :) Lucas's answer is great. For untrusted input you can make a white list of allowed symbols/operators. (define do-something (lambda (op) (cond ((equal? op `+) +) ((equal? op `-) -) ((equal? op `*) *) ((equal? op `/) /) ((equal? op `^) ^)))) ((do-something `+) 1 2) Newbie too

Check for a prime number using recursive helper function

牧云@^-^@ 提交于 2019-12-02 00:25:22
I am trying to check if a number is prime using recursion. I was required to use a recursive helper function, but I am not sure how I should implement it. I think I know the algorithm, but I've never tried to use a recursive helper function in Racket. This is my current thoughts: See if n is divisible by i = 2 Set i = i + 1 If i^2 <= n continue. If no values of i evenly divided n , then it must be prime. This is what I have so far... (define (is_prime n) (if (<= n 1) #f (if (= (modulo n 2) 0) #f ) What would be a good approach using a recursive helper function?? Thanks! Using a helper simply