function call witn two string parameters in LISP.

5 views
Skip to first unread message

juhyu...@gmail.com

unread,
Oct 7, 2016, 2:24:48 AM10/7/16
to cl-test-grid


I created a function which gets two string parameters. The function simply adds each string length. below is a code.


(defun add_twostring_length (mystr1 mystr2)
(+ (length mystr1) (length mystr2))
)


    
When I call `add_twostring_length` function like this,

> (add_twostring_length "cpp" "lisp")

output is correct. **7**

But, when I call the same function in the manner of using comma,

> (add_twostring_length "cpp", "lisp")

I got an error message.


Error: Comma not inside a backquote.

  [condition type: READER-ERROR]


I want to call function in the manner of  (add_twostring_length "cpp", "lisp")

Where should I modify? blue box(function parameters)? or green underline(function body)?
please give me some hints. Below is picture of my code.


Mark Safronov

unread,
Oct 7, 2016, 8:01:09 AM10/7/16
to cl-tes...@googlegroups.com

First question is WHY WOULD YOU WANT THIS:


> I want to call function in the manner of  (add_twostring_length "cpp", "lisp")

You do know that you're in Lisp and you do not need commas, right?


Best regards,
Mark

http://about.me/hijarian
07.10.2016 09:24, juhyu...@gmail.com пишет:
--
You received this message because you are subscribed to the Google Groups "cl-test-grid" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cl-test-grid...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

박주현

unread,
Oct 7, 2016, 8:42:41 AM10/7/16
to cl-tes...@googlegroups.com
generally, lisp doesn't use commas. however when I parse a long text structured like that "something 1", "something 2", "something 3" ... I want to use the raw data.

I modified part of that code like this.

(defun add_twostring_length (mystr1 comma mystr2) 
        (+ (length mystr1) (length mystr2))
)

I added comma in function parameter.
That code can generate correct answer "specific" input.

(add_twostring_length "cpp" "," "lisp")

Notice I added ","

But eventually I want to use following input.

(add_twostring_length "cpp", "lisp")

Could you give me some hints?

To unsubscribe from this group and stop receiving emails from it, send an email to cl-test-grid+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "cl-test-grid" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cl-test-grid/oU2VVzwU0b4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to cl-test-grid+unsubscribe@googlegroups.com.

Mark Safronov

unread,
Oct 7, 2016, 8:55:32 AM10/7/16
to cl-tes...@googlegroups.com, Anton Vodonosov

OK, I must note that cl-test-grid is not a place to discuss general lisp-related topics. I guess it's quite rude to Anton to continue this offtopic, no matter how curious it may be.

To sum up, it all depends on what your actual input and expected output data is!

If you want to count the total length of the strings in the given argument list, use something like this:

(defun total_strings_length (&rest input-strings)
  (apply '+ (map 'length input-strings)))

Usage is like this:

? (total_strings_length "one" "two" "three")
11

Comma is absolutely unnecessary for you, just forget about it and/or remove it from the input at separate preprocessing stage. Creating a function which correctly parses calls like (add_twostring_length "cpp", "lisp") involves creating macros supporting this foreign syntax and I fail to understand what problem it will solve.


Best regards,
Mark

http://about.me/hijarian
07.10.2016 15:42, 박주현 пишет:
To unsubscribe from this group and stop receiving emails from it, send an email to cl-test-grid...@googlegroups.com.

박주현

unread,
Oct 7, 2016, 9:02:03 AM10/7/16
to cl-tes...@googlegroups.com
ok thank you.
Reply all
Reply to author
Forward
0 new messages