• Re: Poll: StudlyChallenge

    From B. Pym@21:1/5 to Kenny Tilton on Sat Sep 14 20:47:37 2024
    XPost: comp.lang.scheme

    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)))

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)