Welcome to the CHICKEN Scheme pasting service

POSIX nanoseconds pasted by jacius on Wed Jan 20 22:11:28 2016


;;; WARNING: UNTESTED!

;;; Uses the POSIX clock_gettime C function to return the current
;;; nanoseconds. Suitable only for Linux and BSD. Not portable to
;;; Windows or Mac.

(module nanoseconds (current-nanoseconds)
  (import chicken scheme foreign)

  (foreign-declare "#include <time.h>")

  ;; Return the current nanoseconds, or -1 if an error occurs.
  (define current-nanoseconds
    (foreign-lambda* long ()
      "struct timespec ts;"
      "int success = clock_gettime(CLOCK_REALTIME, &ts);"
      "if (-1 == success) {"
      "  C_return(-1);"
      "} else {"
      "  C_return(ts.tv_nsec);"
      "}")))


(import nanoseconds)
(print (current-nanoseconds))

Great! added by IstiCusi on Wed Jan 20 22:42:48 2016

Thanks you very much, Jacius! 
Was my first day with scheme and you made a good
day out of it. 

Your annotation:

Enter a new annotation:

Your nick:
The title of your paste:
Your paste (mandatory) :
Name of the CHICKEN extension manager:
Visually impaired? Let me spell it for you (wav file) download WAV