[plt-scheme] possibly silly question

From: Jos Koot (jos.koot at telefonica.net)
Date: Fri Nov 27 04:25:40 EST 2009

I think the following is ment:

(local ((define number+ +))
       (local
        ((define +
                (lambda x
                        (cond
                         ((null? x) 0)
                         ((string? (car x)) (apply string-append x))
                         (else (apply number+ x))))))
       
       (define str "sdfdsf")
       (display (+ "something" str))
       (newline)
       (display (+ 1 2 3))))

Jos
  ----- Original Message ----- 
  From: Laurent 
  To: Matthias Felleisen 
  Cc: Charlie Smith ; plt-scheme 
  Sent: Friday, November 27, 2009 8:48 AM
  Subject: Re: [plt-scheme] possibly silly question





  On Thu, Nov 26, 2009 at 18:23, Matthias Felleisen <matthias at ccs.neu.edu> wrote:


    (define str "sdfdsf")
    (display (string-append "something" str))

    ;; if you really like the + symbol, define + to do some more locally

    #lang scheme

    (local ((define + (let ((+ +)) (lambda x
                                    (cond
                                      [(null? x) 0]
                                      [(string? (car x)) (apply string-append x)]
                                      [else (apply + x)])))))

     (define str "sdfdsf")
     (display (string-append "something" str)))



  On the last line, Matthias probably meant:
   (display (+ "something" str)))

  which shows that + ca be redefined locally to act like string-append (and still keep its usual meaning on numbers).

  Laurent

   


    On Nov 26, 2009, at 7:43 AM, Charlie Smith wrote:

    > hi
    >
    > i'd like to know if there is some way of adding strings (sorry, i don't what the correct term for this is, maybe variable interpolation?) like for example in ruby it would be like
    >
    > str = "sdfdsf"
    > puts "something" + str
    > output: "somethingsdsdf"
    >
    > the function string-append isn't what I want, because i would be adding strings somewhat arbitarily in between other strings
    >
    >
    >
    >

    > _________________________________________________
    >  For list-related administrative tasks:
    >  http://list.cs.brown.edu/mailman/listinfo/plt-scheme

    _________________________________________________
     For list-related administrative tasks:
     http://list.cs.brown.edu/mailman/listinfo/plt-scheme





------------------------------------------------------------------------------


  _________________________________________________
    For list-related administrative tasks:
    http://list.cs.brown.edu/mailman/listinfo/plt-scheme
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20091127/72d4f93b/attachment.html>

Posted on the users mailing list.