[ 3 / biz / cgl / ck / diy / fa / ic / jp / lit / sci / vr / vt ] [ index / top / reports ] [ become a patron ] [ status ]
2023-11: Warosu is now out of extended maintenance.

/sci/ - Science & Math


View post   

File: 7 KB, 88x85, customLogo[1].gif_revisi.png [View same] [iqdb] [saucenao] [google]
2553378 No.2553378 [Reply] [Original]

anyone know the programming language scheme?
if so, how do you remove, from a list of strings, the strings that have NO LETTERS, i.e. i want my function to take something like:
(list "30-20" "hi" "--" "tomato" "59" "toronto")
and return:
(list "hi" "tomato" "toronto")
thanks in advance

>> No.2553738

bump

>> No.2553795

I'm not schemer, but it must have something like filter from haskell... a function that takes some predicate and a list and returns only the elements satisfying the predicate.
And writing a function that return nil (amirite ?) if string has no letters in it is easy.

>> No.2553809
File: 32 KB, 360x507, trolledsoftly.jpg [View same] [iqdb] [saucenao] [google]
2553809

>>2553378
>toronto

I see what you did there o_O

bump for helping anon write a program

>> No.2554109

>>2553378
Is common lisp fine too ?

(defun myFilter (p xs)
(if (null xs)
()
(let ((x (car xs)))
(if (funcall p x)
(cons x (myFilter p (cdr xs)))
(myFilter p (cdr xs))))))

(defun fine-string (xs)
(if (equal xs "")
nil
(if (alphanumericp (char xs 0))
T
(fine-string (subseq xs 1)))))

(defun lolfunction (xs)
(myFilter 'fine-string xs))

>> No.2554140

Scheme is a shitty disgusting language.

>> No.2554307

>>2554140
my school doesn't seem to think so...
>>2554109
i see some similarities, but i'll admit i don't understand it completely.
in any case, alphanumericp seems to be a distinguishing feature...I can only convert a string into a list of characters, but not numbers...so it'd be identified as (cons #\3 (cons #\2 (cons #\j empty))) but i don't know of any scheme functions that would identify the #\3 apart from #\j (distinguish a number from a letter)
but thanks a lot, i'm still looking into it

>> No.2556342

bump

>> No.2556370

>>2554109
>(myFilter p (cdr xs))))))
>(cdr xs))))))
>))))))

>> No.2556457

This is what you want, OP. http://srfi.schemers.org/srfi-1/srfi-1.html#FilteringPartitioning
Of course, replacing "even" with your own predicate. I would use regular expressions.
http://evalwhen.com/pregexp/index.html

>>2554140
Go shoot yourself and never touch a computer again.

>>2556370
The expressive power of LISP and related languages more than makes up for the minor inconvenience of having to hit shift+0 a few times.

>> No.2556474

got it...
atrocious but it works

(define (clean-page page)
(cond
[(empty? page) empty]
[(or (number? (string->number (list->string (list (first (string->list (first page)))))))
(cond
[(empty? (rest (string->list (first page)))) false]
[else (number? (string->number (list->string (list (second (string->list (first page)))))))]))
(clean-page (rest page))]
[else (cons (list->string (clean (string->list (first page)))) (clean-page (rest page)))]))

took the first element of a list (a string), turned it into a list, took singled out the first/second (i.e. 1980, or (1980)) element of that list, converted that into a string since it's only from a string into which i can determine whether the character is a number...
thanks for all the help