* concat vs format
@ 2018-12-09 3:50 Jean-Christophe Helary
2018-12-09 4:09 ` Drew Adams
0 siblings, 1 reply; 9+ messages in thread
From: Jean-Christophe Helary @ 2018-12-09 3:50 UTC (permalink / raw)
To: help-gnu-emacs
Is there a difference between:
(concat firstPartofURL secondPartofURL)
and
(format "%s%s" firstPartofURL secondPartofURL)
?
Jean-Christophe Helary
-----------------------------------------------
http://mac4translators.blogspot.com @brandelune
^ permalink raw reply [flat|nested] 9+ messages in thread
* RE: concat vs format
2018-12-09 3:50 concat vs format Jean-Christophe Helary
@ 2018-12-09 4:09 ` Drew Adams
2018-12-09 10:02 ` Jean-Christophe Helary
0 siblings, 1 reply; 9+ messages in thread
From: Drew Adams @ 2018-12-09 4:09 UTC (permalink / raw)
To: Jean-Christophe Helary, help-gnu-emacs
> Is there a difference between:
> (concat firstPartofURL secondPartofURL) and
> (format "%s%s" firstPartofURL secondPartofURL)?
If both args are strings then no; the result
is the same. But the functions are very
different - they take different args and,
aside from some cases like this one where
the result is the same for some args, their
uses/purposes are different.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: concat vs format
2018-12-09 4:09 ` Drew Adams
@ 2018-12-09 10:02 ` Jean-Christophe Helary
2018-12-09 11:30 ` Stefan Huchler
0 siblings, 1 reply; 9+ messages in thread
From: Jean-Christophe Helary @ 2018-12-09 10:02 UTC (permalink / raw)
To: help-gnu-emacs
> On Dec 9, 2018, at 13:09, Drew Adams <drew.adams@oracle.com> wrote:
>
>> Is there a difference between:
>> (concat firstPartofURL secondPartofURL) and
>> (format "%s%s" firstPartofURL secondPartofURL)?
>
> If both args are strings then no; the result
> is the same. But the functions are very
> different - they take different args and,
> aside from some cases like this one where
> the result is the same for some args, their
> uses/purposes are different.
Thank you.
I'm trying to create URLs from dates and at one point I get a concat that outputs "/path/to/url/..." instead of "/path/to/url/12/04/index.html".
I checked the code and put format instead of concat and got the same result. All the things I try to concat are strings that I progressively build over other strings, and edebug gives me correct values up to the point where the wrong string is created...
I'm going to re-check the whole thing...
Jean-Christophe Helary
-----------------------------------------------
http://mac4translators.blogspot.com @brandelune
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: concat vs format
2018-12-09 10:02 ` Jean-Christophe Helary
@ 2018-12-09 11:30 ` Stefan Huchler
2018-12-09 13:42 ` Jean-Christophe Helary
0 siblings, 1 reply; 9+ messages in thread
From: Stefan Huchler @ 2018-12-09 11:30 UTC (permalink / raw)
To: help-gnu-emacs
I run into a similar problem when I used the prin1 function. It had to
do with the default value auf print-length which was to low.
can you put a (let* ((print-length 5000)) around your code and test
that? Or look up the variable if it could have something todo with your
problem.
Jean-Christophe Helary <brandelune@gmail.com> writes:
>> On Dec 9, 2018, at 13:09, Drew Adams <drew.adams@oracle.com> wrote:
>>
>>> Is there a difference between:
>>> (concat firstPartofURL secondPartofURL) and
>>> (format "%s%s" firstPartofURL secondPartofURL)?
>>
>> If both args are strings then no; the result
>> is the same. But the functions are very
>> different - they take different args and,
>> aside from some cases like this one where
>> the result is the same for some args, their
>> uses/purposes are different.
>
> Thank you.
>
> I'm trying to create URLs from dates and at one point I get a concat that outputs "/path/to/url/..." instead of "/path/to/url/12/04/index.html".
> I checked the code and put format instead of concat and got the same
> result. All the things I try to concat are strings that I
> progressively build over other strings, and edebug gives me correct
> values up to the point where the wrong string is created...
>
> I'm going to re-check the whole thing...
>
> Jean-Christophe Helary
> -----------------------------------------------
> http://mac4translators.blogspot.com @brandelune
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: concat vs format
2018-12-09 11:30 ` Stefan Huchler
@ 2018-12-09 13:42 ` Jean-Christophe Helary
2018-12-09 14:15 ` Stefan Monnier
2018-12-09 14:57 ` Stephen Berman
0 siblings, 2 replies; 9+ messages in thread
From: Jean-Christophe Helary @ 2018-12-09 13:42 UTC (permalink / raw)
To: help-gnu-emacs
Stephan,
I tried your suggestion but it did not (seem to) work.
But after simplifying the code, I found a simpler way to identify the issue, so that I can show it to the list.
I run edebug on this:
(defun dailyTemplate (myDay)
(interactive (list
(read-number "Date: " (string-to-number (format-time-string "%d")))))
(let* ((myToday (getMyDates myDay))
; (myTomorrow (+ (getMyDates myDay) 84600))
; (myYesterday (- (getMyDates myDay) 84600))
(siteRoot "/Users/suzume/Documents/Code/brandelune.github.io/")
(cssRoot (concat siteRoot "css/" (format-time-string "%Y" myToday) "/"))
And here are the edebug messages:
Edebug: dailyTemplate
[4 times]
Result: "09"
Result: 9 (#o11, #x9, ?\C-i)
Result: 9 (#o11, #x9, ?\C-i)
Result: (9)
[3 times]
Result: 9 (#o11, #x9, ?\C-i)
Result: 1544324400 (#o13403102460, #x5c0c8530)
[2 times]
Result: "/Users/suzume/Documents/Code/brandelune.github.io/"
[2 times]
Result: 1544324400 (#o13403102460, #x5c0c8530)
Result: "2018"
Result: "/Users/suzume/Documents/Code/brandelune.github.io/..."
So, the last concat gives me a path that's not the result of a "concat" on the values that I feed it. Why ?
"myDay" is checked to be between 1 and 31 and "getMyDates" returns this:
(encode-time (list 0 0 12 myDay myMonth myYear nil nil 32400) 'integer)
When I run:
(concat "/Users/suzume/Documents/Code/brandelune.github.io/" "css/" (format-time-string "%Y" 1544324400) "/")
I *do* get what I expect, which is:
"/Users/suzume/Documents/Code/brandelune.github.io/css/2018/"
There is clearly something I do not understand here... :(
Jean-Christophe
> On Dec 9, 2018, at 20:30, Stefan Huchler <stefan.huchler@mail.de> wrote:
>
> I run into a similar problem when I used the prin1 function. It had to
> do with the default value auf print-length which was to low.
>
> can you put a (let* ((print-length 5000)) around your code and test
> that? Or look up the variable if it could have something todo with your
> problem.
>
> Jean-Christophe Helary <brandelune@gmail.com> writes:
>
>>> On Dec 9, 2018, at 13:09, Drew Adams <drew.adams@oracle.com> wrote:
>>>
>>>> Is there a difference between:
>>>> (concat firstPartofURL secondPartofURL) and
>>>> (format "%s%s" firstPartofURL secondPartofURL)?
>>>
>>> If both args are strings then no; the result
>>> is the same. But the functions are very
>>> different - they take different args and,
>>> aside from some cases like this one where
>>> the result is the same for some args, their
>>> uses/purposes are different.
>>
>> Thank you.
>>
>> I'm trying to create URLs from dates and at one point I get a concat that outputs "/path/to/url/..." instead of "/path/to/url/12/04/index.html".
>> I checked the code and put format instead of concat and got the same
>> result. All the things I try to concat are strings that I
>> progressively build over other strings, and edebug gives me correct
>> values up to the point where the wrong string is created...
>>
>> I'm going to re-check the whole thing...
>>
>> Jean-Christophe Helary
>> -----------------------------------------------
>> http://mac4translators.blogspot.com @brandelune
>
>
Jean-Christophe Helary
-----------------------------------------------
http://mac4translators.blogspot.com @brandelune
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: concat vs format
2018-12-09 13:42 ` Jean-Christophe Helary
@ 2018-12-09 14:15 ` Stefan Monnier
2018-12-09 14:55 ` Jean-Christophe Helary
2018-12-09 14:57 ` Stephen Berman
1 sibling, 1 reply; 9+ messages in thread
From: Stefan Monnier @ 2018-12-09 14:15 UTC (permalink / raw)
To: help-gnu-emacs
> (cssRoot (concat siteRoot "css/" (format-time-string "%Y" myToday) "/"))
BTW, it's recommended to use `expand-file-name` instead of `concat` to
combine a directory name and a relative file name.
E.g.
(cssRoot (file-name-as-directory
(expand-file-name (format-time-string "%Y" myToday)
(expand-file-name "css" siteRoot))))
-- Stefan
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: concat vs format
2018-12-09 14:15 ` Stefan Monnier
@ 2018-12-09 14:55 ` Jean-Christophe Helary
0 siblings, 0 replies; 9+ messages in thread
From: Jean-Christophe Helary @ 2018-12-09 14:55 UTC (permalink / raw)
To: help-gnu-emacs
> On Dec 9, 2018, at 23:15, Stefan Monnier <monnier@iro.umontreal.ca> wrote:
>
>> (cssRoot (concat siteRoot "css/" (format-time-string "%Y" myToday) "/"))
>
> BTW, it's recommended to use `expand-file-name` instead of `concat` to
> combine a directory name and a relative file name.
I'll try this, but would that explain why my concat doesn't work ?
> E.g.
>
> (cssRoot (file-name-as-directory
> (expand-file-name (format-time-string "%Y" myToday)
> (expand-file-name "css" siteRoot))))
Jean-Christophe Helary
-----------------------------------------------
http://mac4translators.blogspot.com @brandelune
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: concat vs format
2018-12-09 13:42 ` Jean-Christophe Helary
2018-12-09 14:15 ` Stefan Monnier
@ 2018-12-09 14:57 ` Stephen Berman
2018-12-09 15:44 ` Jean-Christophe Helary
1 sibling, 1 reply; 9+ messages in thread
From: Stephen Berman @ 2018-12-09 14:57 UTC (permalink / raw)
To: Jean-Christophe Helary; +Cc: help-gnu-emacs
On Sun, 9 Dec 2018 22:42:15 +0900 Jean-Christophe Helary <brandelune@gmail.com> wrote:
> I run edebug on this:
>
> (defun dailyTemplate (myDay)
> (interactive (list
> (read-number "Date: " (string-to-number (format-time-string "%d")))))
> (let* ((myToday (getMyDates myDay))
> ; (myTomorrow (+ (getMyDates myDay) 84600))
> ; (myYesterday (- (getMyDates myDay) 84600))
>
> (siteRoot "/Users/suzume/Documents/Code/brandelune.github.io/")
>
> (cssRoot (concat siteRoot "css/" (format-time-string "%Y" myToday) "/"))
>
> And here are the edebug messages:
>
> Edebug: dailyTemplate
> [4 times]
> Result: "09"
>
> Result: 9 (#o11, #x9, ?\C-i)
>
> Result: 9 (#o11, #x9, ?\C-i)
>
> Result: (9)
> [3 times]
> Result: 9 (#o11, #x9, ?\C-i)
>
> Result: 1544324400 (#o13403102460, #x5c0c8530)
> [2 times]
> Result: "/Users/suzume/Documents/Code/brandelune.github.io/"
> [2 times]
> Result: 1544324400 (#o13403102460, #x5c0c8530)
>
> Result: "2018"
>
> Result: "/Users/suzume/Documents/Code/brandelune.github.io/..."
>
> So, the last concat gives me a path that's not the result of a
> "concat" on the values that I feed it. Why ?
The length of the output in Edebug is constrained by the user option
edebug-print-length, which is 50 by default; by setting that variable to
nil, the output won't be cut off.
Steve Berman
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: concat vs format
2018-12-09 14:57 ` Stephen Berman
@ 2018-12-09 15:44 ` Jean-Christophe Helary
0 siblings, 0 replies; 9+ messages in thread
From: Jean-Christophe Helary @ 2018-12-09 15:44 UTC (permalink / raw)
To: help-gnu-emacs
> On Dec 9, 2018, at 23:57, Stephen Berman <stephen.berman@gmx.net> wrote:
>
>> Result: "/Users/suzume/Documents/Code/brandelune.github.io/ <http://brandelune.github.io/>..."
>>
>> So, the last concat gives me a path that's not the result of a
>> "concat" on the values that I feed it. Why ?
>
> The length of the output in Edebug is constrained by the user option
> edebug-print-length, which is 50 by default; by setting that variable to
> nil, the output won't be cut off.
Thank you Stephan.
I found out that my issue had nothing to do with concat/format but rather with let*/setq.
My first code ran fine with setq, then, after the thread that I started about setq a few days ago, I decided to use let* and let in my code instead. And that's when things started to break. I don't understand why (must be something with variable scope) but for now I need to write something that works and move on.
I'll come back here when I am closer to identifying my issue.
Jean-Christophe Helary
-----------------------------------------------
http://mac4translators.blogspot.com @brandelune
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2018-12-09 15:44 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-12-09 3:50 concat vs format Jean-Christophe Helary
2018-12-09 4:09 ` Drew Adams
2018-12-09 10:02 ` Jean-Christophe Helary
2018-12-09 11:30 ` Stefan Huchler
2018-12-09 13:42 ` Jean-Christophe Helary
2018-12-09 14:15 ` Stefan Monnier
2018-12-09 14:55 ` Jean-Christophe Helary
2018-12-09 14:57 ` Stephen Berman
2018-12-09 15:44 ` Jean-Christophe Helary
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).