Scheme/Dr.Racket Help
1
Name:
Anonymous
2012-10-23 20:56
Using Scheme/DrRacket for this problem:
I need help /g/...
This problem is telling me to do the following:
Create a Scheme function has-consequence? that consumes word (a string with one or more lower-case letters). It produces true if all the letters in word appear in the word “consequence", and false otherwise.
I understand that I have to use recursion and lists for this. So far all I've been able to do is convert the word that I'm supposed to use as a list by doing the following:
string->list "consequence"
However, how do I make the program convert the argument "word" into a list and then compare "consequence" with "word" to see if all characters in the "word" appear in "consequence"?
2
Name:
Anonymous
2012-10-23 20:58
this is not g, get the fuck out
3
Name:
Anonymous
2012-10-23 21:01
*sigh*
4
Name:
Anonymous
2012-10-23 21:02
all $ flip elem "consequence"
5
Name:
Anonymous
2012-10-23 21:04
What?
6
Name:
Anonymous
2012-10-23 21:26
(define (has-consequence? word) (not (not (andmap (lambda x (member (car x) (string->list "consequence"))) (string->list word)))))
7
Name:
Anonymous
2012-10-23 21:36
>>5
>>4 is Haskell.
>>6 is the result of translating
has_consequences = all $ flip elem "consequence"
into Racket.
8
Name:
Anonymous
2012-10-23 22:34
Alright, so you have string, which you are already able to turn into a list via string->list.
What I would do is:
1. Create a procedure to tell you if a given character is in the word consequence.
2. Within another, see if all characters satisfy said condition.
Assuming you don't know reduce, memq, or really, anything else which would have made this a fucking one-liner.
(define (is-in? char sequence)
(and (not (null? sequence))
(or (equal? char (car sequence))
(is-in? char (cdr sequence)))))
(define (combination-of? word char-list)
(define length (string-length word))
(define (combination-of-helper index result)
(if (or (not result) (= index length))
result
(combination-of-helper (+ index 1)
(is-in? (string-ref word index) char-list))))
(combination-of-helper 0 #t))
(combination-of? "c" (string->list "consequence"))
9
Name:
Anonymous
2012-10-23 22:50
Fuck off back to /g/.
10
Name:
Anonymous
2012-10-23 22:51
Use Symta.
11
Name:
Anonymous
2012-10-23 22:52
>>8
Good job! You managed to turn a simple one-liner into a miserable pile of parentheses!
12
Name:
Anonymous
2012-10-23 22:58
Why don't you try Symta?
13
Name:
Anonymous
2012-10-23 22:59
I'm actually interested in this one-liner solution to this.
14
Name:
Anonymous
2012-10-23 23:15
>>2,9
Question about Lisp
Back to /g/.
How new can you possibly be? It's cute that you're try to fit in and all, but fuck off back to /g/, ``please''.
15
Name:
Anonymous
2012-10-23 23:22
>>14
Who are you quoting?
16
Name:
Anonymous
2012-10-23 23:23
>>11
Everyone here can write a one liner for this kiddie shit, I just assumed the least amount of knowledge I could about the OP.
>>6
There was one in
>>13 . The double negation, essentially for type coercion, lets the program accept the empty string as a combination of the characters in "consequence". This one I wrote does not:
(define (has-consequence? word)
(list? (andmap (lambda (c) (memq c (string->list "consequence")))
(string->list word))))
I guess both are valid.
17
Name:
Anonymous
2012-10-23 23:39
>>14
OP posted this on /g/ yesterday.
18
Name:
Anonymous
2012-10-23 23:42
>>14
Now I'm told I'm ``trying to fit in'' when I tell someone to go back to their home.
19
Name:
Anonymous
2012-10-24 1:22
hasConsequence = and . map (`elem` "consequence")
20
Name:
Anonymous
2012-10-24 1:28
>>17
So you were there to witness it.
21
Name:
Anonymous
2012-10-24 1:56
22
Name:
Anonymous
2012-10-24 2:25
W^.∊'consequence'
Where W is the word.
23
Name:
VIPPER
2012-10-24 5:24
I need help /g/...
Yep, go ask there and never come back.
24
Name:
Anonymous
2012-10-24 10:03
>>1 `
>2012
>confusing /prog/ with /g/
I shiggy diggy
25
Name:
Anonymous
2012-10-24 10:10
>>24
le epic meme arrows reddit/b/ro XDDDD
26
Name:
Anonymous
2012-10-25 0:51
>>22
what language is this?
27
Name:
Anonymous
2012-10-25 1:22
28
Name:
Anonymous
2012-10-25 2:20
>>27
Have you tried Symta?
29
Name:
Anonymous
2012-10-25 2:37
>>28
I couldn't get
asdf-install to install the packages it needs.
It looks like my kind of language.