[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: mkstemp strange behavior
From: |
R. Mattes |
Subject: |
Re: mkstemp strange behavior |
Date: |
Wed, 10 Aug 2005 20:18:29 +0200 |
On Wed, 2005-08-10 at 13:54 -0400, Alan Grover wrote:
> I ran into this too. My reasoning was something like:
>
> The string, "/tmp/XXXXXX" is constructed at reader time. So, there is
> exactly one string. The "let" creates a new variable each time you call
> "test", but the variable is bound to the same string.
Besides: string constants (i.e. "xxx" stuff) are _inmutable_ in scheme.
> Mkstemp modifies the (one and only) string the first time.
Yes, modifying a constant is not a good idea (and guile should croack
allready the first time).
Just my 0.02$
Ralf Mattes
> If you force the value to be computed at exec time, the problem should
> go away: (string-append "" "/tmp/XXXXXX").
>
> You could test my theory by something like:
>
> (define (test) (let ((filename "/tmp/XXXXXX")) filename))
>
> (display (eq? (test) (test)))
>
> Which yields #t for me. And, (eq? "/tmp/XXXXXX" "/tmp/XXXXXX") yields
> #f, for comparison.
>
> José Roberto B. de A. Monteiro wrote:
> > Hello all!
> >
> > I was trying to use mkstemp! in my program, instead of tmpnam, but I have no
> > success... I mkstemp! is getting me confused. It alters original string, so
> > we can easely have the name of temporary file.
> >
> > But, with following code, I suposed it would work, but it is reusing an old
> > string:
> >
> > #!/usr/bin/guile \
> > -s
> > !#
> >
> > (define (test)
> > (let ((filename "/tmp/XXXXXX")
> > (tmp #f))
> > (format #t "before: filename=~A\n" filename)
> > (set! tmp (mkstemp! filename))
> > (format #t "after : filename=~A\n" filename)
> > (close tmp)))
> >
> > (format #t "First call...\n")
> > (test)
> > (format #t "Second call...\n")
> > (test)
> >
> > And the result of this code is:
> >
> > First call...
> > before: filename=/tmp/XXXXXX
> > after : filename=/tmp/HGLPtZ
> > Second call...
> > before: filename=/tmp/HGLPtZ
> > ERROR: In procedure mkstemp!:
> > ERROR: Invalid argument
> >
> > I can not figure out why the string is not set to /tmp/XXXXXX in the second
> > call...
> >
> > Some help!?
> >
> > Regards
> > Betoes
> >
> >
> > _______________________________________________
> > Guile-user mailing list
> > address@hidden
> > http://lists.gnu.org/mailman/listinfo/guile-user
> >
>
> _______________________________________________
> Guile-user mailing list
> address@hidden
> http://lists.gnu.org/mailman/listinfo/guile-user