Re: Poll: StudlyChallenge

Liste des GroupesRevenir à cl lisp 
Sujet : Re: Poll: StudlyChallenge
De : Nobody447095 (at) *nospam* here-nor-there.org (B. Pym)
Groupes : comp.lang.lisp comp.lang.scheme
Date : 14. Sep 2024, 22:47:37
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vc4sp8$1m02t$1@dont-email.me>
User-Agent : XanaNews/1.18.1.6
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)
  ;; Clojure-style threading or pipelining.
  (-> name
    ((swap regexp-replace-all) #/[A-Z]/   "-\0")
    (string-trim   #\-)
    string-downcase
    string->symbol))

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


Given:

(define-syntax ->
  (syntax-rules ()
    [(_ x)  x]
    [(_ x (y more ...) z ...)
     (-> (y x more ...) z ...)]
    [(_ x y z ...)
     (-> (y x) z ...)]))

(define (swap func)
  (lambda (a b . args)
    (apply func b a args)))

Date Sujet#  Auteur
14 Sep22:47 o Re: Poll: StudlyChallenge1B. Pym

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal