Comments on: Lisp, a question about concatenation, step #4 http://ave1.org/2019/lisp-a-question-about-concatenation-step-4/ Tue, 06 Oct 2020 17:02:28 +0000 http://polimedia.us hourly 1 By: Mircea Popescu http://ave1.org/2019/lisp-a-question-about-concatenation-step-4/#comment-251 Mircea Popescu Thu, 01 Aug 2019 00:08:18 +0000 http://ave1.org/?p=276#comment-251 Your notion of strings is not even <a href="http://btcbase.org/log-search?q=from%3Adiana+C+strings" rel="nofollow">C</a>, seems rather php/python/perl etc, where "hurr"."durr"="hurrdurr" as a "just like that" thing. That dot is not merely an undefined operation in lisp, it is an <em>undefinable</em> operation, and for fundamental reasons, having to do with the very definitions of terms. You can start the trip this way : write down your own definition of "string", see what lisp primitive it matches ; maybe notice in the process <em>you didn't even think before a definition is needed</em>, "shit should just work", and all that. Why do you want strings ? What do you use them for ? Why are you using strings for that ? And so following. Your notion of strings is not even C, seems rather php/python/perl etc, where "hurr"."durr"="hurrdurr" as a "just like that" thing.

That dot is not merely an undefined operation in lisp, it is an undefinable operation, and for fundamental reasons, having to do with the very definitions of terms. You can start the trip this way : write down your own definition of "string", see what lisp primitive it matches ; maybe notice in the process you didn't even think before a definition is needed, "shit should just work", and all that.

Why do you want strings ? What do you use them for ? Why are you using strings for that ? And so following.

]]>
By: ave1 http://ave1.org/2019/lisp-a-question-about-concatenation-step-4/#comment-250 ave1 Wed, 31 Jul 2019 18:09:56 +0000 http://ave1.org/?p=276#comment-250 Stan: Thank you, yes but I wanted to avoid "format" for now (as I can think of the same use cases of lists with other items). And loop will probably be next on the menu, but I hoped there would be other methods. I'm probably still thinking too much in Python idoms (with *join* of strings) MP I do not understand, is this something that can be explained? I can also image I'll have to continue on this path for a long <a href="http://trilema.com/2015/the-rabbi-and-the-ewe/" rel="nofollow">while</a> to get an inkling. Stan:

Thank you, yes but I wanted to avoid "format" for now (as I can think of the same use cases of lists with other items). And loop will probably be next on the menu, but I hoped there would be other methods.

I'm probably still thinking too much in Python idoms (with *join* of strings)

MP

I do not understand, is this something that can be explained? I can also image I'll have to continue on this path for a long while to get an inkling.

]]>
By: Mircea Popescu http://ave1.org/2019/lisp-a-question-about-concatenation-step-4/#comment-248 Mircea Popescu Wed, 31 Jul 2019 17:28:01 +0000 http://ave1.org/?p=276#comment-248 The problem is your notion of strings. The problem is your notion of strings.

]]>
By: Stanislav Datskovskiy http://ave1.org/2019/lisp-a-question-about-concatenation-step-4/#comment-247 Stanislav Datskovskiy Wed, 31 Jul 2019 16:02:01 +0000 http://ave1.org/?p=276#comment-247 Re: 2: "format" and "loop" are made of lisp macros. Their text is reproduced in CLTL2. The idea was, if they did not exist, will end up written regardless, so may as well standardize. CL programmer is not forced to use them in any sense, but you will encounter them in published programs, so must at least know how to read. Re: 2: "format" and "loop" are made of lisp macros. Their text is reproduced in CLTL2.

The idea was, if they did not exist, will end up written regardless, so may as well standardize. CL programmer is not forced to use them in any sense, but you will encounter them in published programs, so must at least know how to read.

]]>
By: spyked http://ave1.org/2019/lisp-a-question-about-concatenation-step-4/#comment-246 spyked Wed, 31 Jul 2019 14:57:42 +0000 http://ave1.org/?p=276#comment-246 Unfortunately (apply #'concatenate 'string list) has the problem that on *some* implementations it might hit the call-arguments-limit wall, i.e. the total number of parameters (including the length of the list) shouldn't be higher than that. See <a href="http://www.lispworks.com/kb/4fbc798cb17237ca852566da005fcc79.html" rel="nofollow">discussion</a> for example. One problem with concatenate itself would be that it does a lot of copying if applied repeatedly (in conjunction with reduce). A more conservative (yet less legible) approach would be to pre-allocate a string with the size being that of the sum of all constituent strings, then repeatedly applying "replace" to fill in the target string. For example CL-WHO has <a href="http://coad.thetarpit.org/cl-who/c-who.lisp.html#L202" rel="nofollow">string-list-to-string</a> which works exactly like this. Unfortunately (apply #'concatenate 'string list) has the problem that on *some* implementations it might hit the call-arguments-limit wall, i.e. the total number of parameters (including the length of the list) shouldn't be higher than that.

See discussion for example.

One problem with concatenate itself would be that it does a lot of copying if applied repeatedly (in conjunction with reduce). A more conservative (yet less legible) approach would be to pre-allocate a string with the size being that of the sum of all constituent strings, then repeatedly applying "replace" to fill in the target string. For example CL-WHO has string-list-to-string which works exactly like this.

]]>