Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Why C/C++ for system programming?

Name: Anonymous 2012-03-08 5:18

It is unsafe, verbose and not particularly fast. Why I'm writing much more readable code with Lisp, using the same API?

Lisp:

(defun folder-p (path) (w/opendir (dir path) (not (null-pointer-p dir))))
(defun file-p (path)
  (unless (folder-p path)
    (w/fopen (f path "r")
      (not (null-pointer-p f)))))


C/C++:

int folderP(char *Name) {
  DIR *Dir;
  struct dirent *Ent;
  if(!(Dir = opendir(Name))) return 0;
  closedir(Dir);
  return 1;
}

int fileP(char *Name) {
  FILE *F;
  if (folderP(Name)) return 0;
  F = fopen(Name, "r");
  unless (F) return 0;
  fclose (F);
  return 1;
}

Name: Anonymous 2012-03-08 17:59

just use both.


C++ to memory map pointerless c structs of your data and then access that from the common lisp foreign data access.

the struct field complies down into 2 instructions and so there's no performance penalty to accessing C instead of common lisp objects.

the lisp garbage collector will never see the data, each pointer to a c object is simply a fixnum and you only ever have to wrap it in lisp to improve debuggability

to allow the lisp to compile into efficent assembly, you can use lots of macros but avoid closures, generics and fancy sequence functions.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List