[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

Re: Poll: StudlyChallenge

William James

7/22/2015 8:33:00 PM

Kenny Tilton wrote:

> (defun lisp-fn (n$ &aux ln)
> (dotimes (n (length n$) (intern (coerce (nreverse ln) 'string)))
> (let ((c (elt n$ n)))
> (when (and (upper-case-p c)
> (or (lower-case-p (elt n$ (1- n)))
> (lower-case-p (elt n$ (1+ n)))))
> (push #\- ln))
> (push (char-upcase c) ln))))
>
> > (lisp-fn "sTuDlYcApS")
> S-TU-DL-YC-AP-S

Gauche Scheme:

(use srfi-13 :only (string-downcase string-trim))

(define (de-stud name)
(string->symbol
(string-downcase
(string-trim
(regexp-replace-all #/[A-Z]/ name "-\\0")
#\-))))

(de-stud "XsTuDLYcApS")
===>
xs-tu-d-l-yc-ap-s

--
Swedes are now in many ways treated as second-class citizens in their own
country. The very word "Swede" has been given a negative connotation. This kind
of project has now been introduced all over Western Europe.
fjordman.blogspot.ca/2005/05/is-swedish-democracy-collapsing.html
1 Answer

William James

1/16/2016 10:35:00 AM

0

WJ wrote:

> Kenny Tilton wrote:
>
> > (defun lisp-fn (n$ &aux ln)
> > (dotimes (n (length n$) (intern (coerce (nreverse ln) 'string)))
> > (let ((c (elt n$ n)))
> > (when (and (upper-case-p c)
> > (or (lower-case-p (elt n$ (1- n)))
> > (lower-case-p (elt n$ (1+ n)))))
> > (push #\- ln))
> > (push (char-upcase c) ln))))
> >
> > > (lisp-fn "sTuDlYcApS")
> > S-TU-DL-YC-AP-S
>
> Gauche Scheme:
>
> (use srfi-13 :only (string-downcase string-trim))
>
> (define (de-stud name)
> (string->symbol
> (string-downcase
> (string-trim
> (regexp-replace-all #/[A-Z]/ name "-\\0")
> #\-))))
>
> (de-stud "XsTuDLYcApS")
> ===>
> xs-tu-d-l-yc-ap-s

MatzLisp (Ruby):

def de_stud word
word.each_char.map{|c|
if c == c.upcase
"-#{ c.downcase }"
else
c
end}.join
end

de_stud "sTuDlYcApS"
===>
"s-tu-dl-yc-ap-s"

--
Amazon bans book. After nearly a month on the site, all traces of the book and
its 80 reviews have been removed.
http://jamesfetzer.blogspot.com/2015/11/debunking-sandy-hook-debunk...
https://www.youtube.com/watch?v=E...