new string quotes macro

Started by Excalibor, September 21, 2004, 07:13:20 AM

Previous topic - Next topic

Excalibor

Hi all,



this is probably either stupidly easy or really hard/impossible to do, but in any case I am mid-way and a bit lost, so I will appreciate the help.



The case is that I dislike the [text][/text] things we have to use for >2kb strings (I guess this limitation for "" {} is a design tradeoff) because it's so unlispy...



so I decided to put the macros into work:



(define-macro (text)

  (eval (join (list '[text] (args) '[/text]) " ")))



now you start to see my problem... the string is parsed before the (quote) can quote it...



Second try:



(define-macro (text)

  (eval (join (list "[text]" (string (args)) "[/text]") " "))))



and this produces the funny result:



(text hello there dude!)

"[text] (hello there dude!) [/text]"



even playing around with (join (list (string (args) " "))) and so on works as badly as the previous solutions...



I wonder if using simply (string) would work... (tested it, and it doesn't exactly work... and I'm not sure it would work for >2kb args list...)



any ideas?

thank!

david

Lutz

#1
just do:



(define (text str) (append "[text]" str "[/text]"))





(text "hello") => "[text]hello[/text]"



of course when you try the function interactiveley the quotes will be converted to [text] - tags on a big string in the console. But if you right it to a file it will be ok:



(write-file "strfile" (text big-str))



Your macro would also work if you do it like this:



(define-macro (text)

(append "[text]" (join (map string (map eval (args)))) "[/text]"))



(text "hi " "there") => "[text]hi there[/text]"



The {,} where introduced to make work with Tcl/Tk and HTML easier.



Lutz

Excalibor

#2
Thanks, Lutz



but I'd like to get rid of the quotes in the arguments (that's why I was trying a macro) so I can write:



(text

Once upon a time in a far away land

there was a little prince that an evil princess had transformed into a husband)



that would be nice, I like it more than the [text][/text] thing... (been working with XML as of late, I'm starting to hate  that of closing tags... BTW, does [hello there dude] means anything? )



laters!

david

Lutz

#3
You can do this:

(define-macro (text)
   (append "[text]" (join (map name (args)) " ") "[/text]"))

(text hello there dude) => "[text]hello there dude[/text]"


You could use 'string' instead of name, but that would prepend the context name, if you call the function from a different context/namespace. 'name' will just take the name of a symbol without the potential context prefix.



'dude' is a street/slang word for a person, you could say instead "hello there man" or something like that.



Lutz

Excalibor

#4
Quote from: "Lutz"


...



You could use 'string' instead of name, but that would prepend the context name, if you call the function from a different context/namespace. 'name' will just take the name of a symbol without the potential context prefix.



'dude' is a street/slang word for a person, you could say instead "hello there man" or something like that.



Lutz


Ah, that's exactly what I wanted (except for a minor side effect when the text contains characters not allowed in a symbols like ",", but I can live without that, or get used to the [text][/text] thing...



as for the hello there dude, thanks for the slang explanation, but I was actually refering to the use of [] around the text. {} is equivalent to "" and thus only useful for <2Kb strings; if [] isn't used anywhere in newLISP (and I haven't found any other use except for [text][/text]), we could use it like other string quotes, maybe equivalent to [text][/text] or maybe not... I particularly love Perl quotes power, we may use [hello there] as defining a string without limits in size, and with some other interesting meaning... or maybe  [[hello there]] so it's easier to see...



just thinking aloud out a little bit...



laters!

Lutz

#5
we can make it somehow configurable



Lutz