News for hackers. Stuff that matters.
Re:fork() can fail by tedunangst on Wednesday August 20, 2014 @06:27PM (#8205023)
What's wrong with the C version?

    char *dir = "/foo";
    mkdir(dir, 0700);
    if (chdir(dir) == 0)
        delete_all_files();
Re:fork() can fail by swah on Wednesday August 20, 2014 @06:36PM (#8205051)
Nothing, of course. I just find the macros that give you a "modified environment" to run some code short and sweet.

with-temp-buffer is another example: a macro that bridges the functions for "string manipulation" and the ones for "buffer manipulation", since you start writing stuff this way:

  (defun replace-in-string (str from to) 
    (with-temp-buffer
      (insert str)
      (beginning-of-file)
      ;;; Here you can use all your normal text editing commands
      (replace-regexp from to nil t)         
      (buffer-string)))
Lots of dirty manipulation, but from outside its a pure function, and doesn't change the editor state in any way after it runs.
Re:fork() can fail by qewrffewqwfqew on Wednesday August 20, 2014 @10:30PM (#8205694)
That's incomplete in that it doesn't automatically chdir back. A proper block-scope "with-" macro will wrap the body in something like:

    char *olddir = getcwd();
    chdir(newdir);
    try {
        do_stuff();
    } finally {
        chdir(olddir);
    }
Re:fork() can fail by jacquesm on Thursday August 21, 2014 @02:51AM (#8206168)
'try' and 'finally' are in C now? Someone should warn the GCC guys they're behind the times.

Also, getcwd has a size parameter these days, and of course you want to check if the getcwd actually worked.

Re:fork() can fail by xxs on Thursday August 21, 2014 @03:52AM (#8206301)
The OP said: wrap in a macro having similar properties (ala pseudo code).
Re:fork() can fail by jacquesm on Thursday August 21, 2014 @06:47AM (#8206711)
Good luck writing a macro in C to express language functionality for which you don't have the primitives. It's not exactly lisp. Think of C macros as a way to save you some typing and lisp macros as a way to extend the language.
Re:fork() can fail by tedunangst on Thursday August 21, 2014 @10:08AM (#8207381)
setjmp and longjmp are sufficient building blocks for this.
Re:fork() can fail by xxs on Thursday August 21, 2014 @08:19AM (#8206955)
you can definitely save the chdir and restore it macro.
Re:fork() can fail by xxs on Thursday August 21, 2014 @03:51AM (#8206300)
Any multithreaded code will be destroyed if relying on chdir. chdir should be deprecated, as resolving relative to is just trivial in an application.