[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

B. C to Scheme mapping

For the convenience of the programmers familiar to C, I composed a simple table of C operators and library functions with the corresponding Scheme functions.

+
R5RS arithmetic procedure +. See section 6.2.4 Arithmetics.
+=
Gauche inc! macro. See section 4.4 Assignments.
-
R5RS arithmetic procedure -. See section 6.2.4 Arithmetics.
-=
Gauche dec! macro. See section 4.4 Assignments.
->
Gauche slot-ref is something close to this. See section 7.5 Accessing Instance.
* (binary)
R5RS arithmetic procedure *. See section 6.2.4 Arithmetics.
* (unary)
No equivalent procedure. Scheme doesn't have explicit notation of pointers.
*=
No equivalent procedure.
/
R5RS arithmetic procedure /. See section 6.2.4 Arithmetics.
/=
No equivalent procedure.
& (binary)
Gauche logand. See section 6.2.6 Bitwise operations.
& (unary)
No equivalent procedure. Scheme doesn't have explicit notation of pointers.
&&
R5RS syntax and. See section 4.5 Conditionals.
&=
No equivalent procedure.
|
Gauche logior. See section 6.2.6 Bitwise operations.
||
R5RS syntax or. See section 4.5 Conditionals.
|=
No equivalent procedure.
^
Gauche logxor. See section 6.2.6 Bitwise operations.
=
R5RS syntax set!. See section 4.4 Assignments.
==
R5RS equivalence procedure, eq?, eqv? and equal?. See section 6.1 Equivalence.
<
<=
R5RS arithmetic procedure < and <=. See section 6.2.3 Numerical comparison. Unlike C operator, Scheme version is transitive.
<<
Gauche ash. See section 6.2.6 Bitwise operations.
<<=
No equivalent procedure.
>
>=
R5RS arithmetic procedure > and >=. See section 6.2.3 Numerical comparison. Unlike C operator, Scheme version is transitive.
>>
Gauche ash. See section 6.2.6 Bitwise operations.
>>=
No equivalent procedure.
%
R5RS operator modulo and remainder. See section 6.2.4 Arithmetics.
%=
No equivalent procedure.
[]
R5RS vector-ref (See section 6.12 Vectors) is something close. Or you can use Gauche's generic function ref (See section 9.18 gauche.sequence - Sequence framework) for arbitrary sequences.
.
Gauche slot-ref is something close to this. See section 7.5 Accessing Instance.
~
Gauche lognot. See section 6.2.6 Bitwise operations.
~=
No equivalent procedure.
!
R5RS procedure not. See section 6.3 Booleans.
!=
No equivalent procedure.
abort
Gauche sys-abort. See section 6.21.1 Program termination
abs
R5RS abs. See section 6.2.4 Arithmetics.
access
Gauche sys-access. See section 6.21.3.4 File stats.
acos
R5RS acos. See section 6.2.4 Arithmetics.
alarm
Gauche sys-alarm. See section 6.21.11 Miscellaneous system calls.
asctime
Gauche sys-asctime. See section 6.21.8 Time.
asin
R5RS asin. See section 6.2.4 Arithmetics.
assert
No equivalent function in Gauche.
atan
atan2
R5RS atan. See section 6.2.4 Arithmetics.
atexit
No equivalent function in Gauche, but the "after" thunk of active dynamic handlers are called when exit is called. See section 6.21.1 Program termination, and See section 6.15.3 Continuation.
atof
atoi
atol
You can use string->number. See section 6.2.5 Numerical conversions.
bsearch
No equivalent function in Gauche.
calloc
Allocation is handled automatically in Scheme.
ceil
R5RS ceiling. See section 6.2.4 Arithmetics.
cfgetispeed
cfgetospeed
cfsetispeed
cfsetospeed
Gauche sys-cfgetispeed, sys-cfgetospeed, sys-cfsetispeed, sys-cfsetospeed. See section 9.20 gauche.termios - Termios.
chdir
Gauche sys-chdir. See section 6.21.3.5 Other file operations.
chmod
Gauche sys-chmod. See section 6.21.3.4 File stats.
chown
Gauche sys-chown. See section 6.21.3.4 File stats
clearerr
Not supported yet.
clock
No equivalent function in Gauche. You can use sys-times to get information about CPU time.
close
You can't directly close the file descriptor, but when you use close-input-port or close-output-port, underlying file is closed. Some port-related functions, such as call-with-output-file, automatically closes the file when operation is finished. The file is also closed when its governing port is garbage collected. See section 6.18.2 Common port operations.
closedir
No equivalent function in Gauche. You can use sys-readdir to read the directory entries at once. See section 6.21.3.1 Directories.
cos
cosh
cos and cosh. See section 6.2.4 Arithmetics.
creat
A file is implictly created by default when you open it for writing. See 6.18.3 File ports for more control over the creation of files.
ctermid
Gauche sys-ctermid. See section 6.21.7 System Inquiry.
ctime
Gauche sys-ctime. See section 6.21.8 Time.
cuserid
No equivalent function. This is removed from the newer POSIX. You can use alternative functions, such as sys-getlogin or sys-getpwuid with sys-getuid.
difftime
Gauche sys-difftime. See section 6.21.8 Time.
div
You can use R5RS quotient and remainder. See section 6.2.4 Arithmetics.
dup
dup2
No equivalent function. If you want to use this function to set up I/Os for the child process, you can use `iomap' argument of sys-exec. See section 6.21.9.1 Fork and exec.
execl
execle
execlp
execv
execve
execvp
Gauche sys-exec. See section 6.21.9.1 Fork and exec. For higher level interface, 9.14 gauche.process - High Level Process Interface.
exit
_exit
Use exit or sys-exit, depends on what you need. See section 6.21.1 Program termination.
exp
R5RS exp. See section 6.2.4 Arithmetics.
fabs
R5RS abs. See section 6.2.4 Arithmetics.
fclose
You can't directly close the file stream, but when you use close-input-port or close-output-port, underlying file is closed. Some port-related functions, such as call-with-output-file, automatically closes the file when operation is finished. The file is also closed when its governing port is garbage collected.
fcntl
Implented as sys-fcntl in gauche.fcntl module. See section 9.5 gauche.fcntl - Low-level file operations.
fdopen
Gauche's open-input-fd-port or open-output-fd-port. See section 6.18.3 File ports.
feof
Not supported yet.
ferror
Not supported yet.
fflush
Gauche's flush. See section 6.18.7 Output.
fgetc
Use read-char or read-byte. See section 6.18.6 Input.
fgetpos
Not supported yet.
fgets
Use read-line or read-block. See section 6.18.6 Input.
fileno
port-file-numer. See section 6.18.2 Common port operations.
floor
R5RS floor. See section 6.2.4 Arithmetics.
fmod
Gauche's fmod.
fopen
R5RS open-input-file or open-output-file corresponds to this operation. See section 6.18.3 File ports.
fork
Gauche's sys-fork. See section 6.21.9.1 Fork and exec.
forkpty
Use sys-forkpty. See section 9.20 gauche.termios - Termios.
fpathconf
Not supported.
fprintf
Not directly supported, but Gauche's format provides similar functionality. See section 6.18.7 Output. SLIB has printf implementation.
fputc
Use write-char or write-byte. See section 6.18.7 Output.
fputs
Use display. See section 6.18.7 Output.
fread
Not directly supported. If you want to read a chunk of bytes, you may be able to use read-block.
free
You don't need this in Scheme.
freopen
Not supported.
frexp
Gauche's frexp
fscanf
Not supported. For general case, you have to write a parser. If you can keep the data in S-exp, you can use read. If the syntax is very simple, you may be able to utilize string-tokenize in srfi-14 (10.7 srfi-13 - String library), and/or regular expression stuff (6.11 Regular expression, also 9.15 gauche.regexp - Regular expression utilities.
fseek
Not implemented yet.
fsetpos
Not implemented yet.
fstat
Gauche's sys-stat. See section 6.21.3.4 File stats.
ftell
Not implemented yet.
fwrite
Not directly supported. If you want to write a chunk of bytes, you can simply use display. See section 6.18.7 Output.
getc
getchar
Use read-char or read-byte. See section 6.18.6 Input.
getcwd
Gauche's sys-getcwd. See section 6.21.7 System Inquiry.
getdomainname
Gauche's sys-getdomainname. See section 6.21.7 System Inquiry.
getegid
Gauche's sys-getegid. See section 6.21.7 System Inquiry.
getenv
Gauche's sys-getenv. See section 6.21.2 Environment Inquiry.
geteuid
Gauche's sys-geteuid. See section 6.21.7 System Inquiry.
gethostname
Gauche's sys-gethostname. See section 6.21.7 System Inquiry.
getgid
Gauche's sys-getgid. See section 6.21.7 System Inquiry.
getgrgid
getgrnam
Gauche's sys-getgrgid and sys-getgrnam. See section 6.21.4.1 Unix Group.
getgroups
Gauche's sys-getgroups. See section 6.21.7 System Inquiry.
getlogin
Gauche's sys-getlogin. See section 6.21.7 System Inquiry.
getpgrp
Gauche's sys-getpgrp. See section 6.21.7 System Inquiry.
getpid
getppid
Gauche's sys-getpid. See section 6.21.7 System Inquiry.
getpwnam
getpwuid
Gauche's sys-getpwnam and sys-getpwuid. See section 6.21.4.2 Unix users.
gets
Use read-line or read-block. See section 6.18.6 Input.
gettimeofday
Gauche's sys-gettimeofday. See section 6.21.8 Time.
getuid
Gauche's sys-getuid. See section 6.21.7 System Inquiry.
gmtime
Gauche's sys-gmtime. See section 6.21.8 Time.
isalnum
Not directly supported, but you can use R5RS char-alphabetic? and char-numeric?. See section 6.8 Characters. You can also use character set. See section 6.9 Character Set, also 10.8 srfi-14 - Character-set library.
isalpha
R5RS char-alphabetic?. See section 6.8 Characters. See also 6.9 Character Set and 10.8 srfi-14 - Character-set library.
isatty
Gauche's sys-isatty. See section 6.21.3.5 Other file operations.
iscntrl
Not directly supported, but you can use (char-set-contains? char-set:iso-control c) with srfi-14. See section 10.8 srfi-14 - Character-set library.
isdigit
R5RS char-numeric?. See section 6.8 Characters. You can also use (char-set-contains? char-set:digit c) with srfi-14. See section 10.8 srfi-14 - Character-set library.
isgraph
Not directly supported, but you can use (char-set-contains? char-set:graphic c) with srfi-14. See section 10.8 srfi-14 - Character-set library.
islower
R5RS char-lower-case?. See section 6.8 Characters. You can also use (char-set-contains? char-set:lower-case c) with srfi-14. See section 10.8 srfi-14 - Character-set library.
isprint
Not directly supported, but you can use (char-set-contains? char-set:printing c) with srfi-14. See section 10.8 srfi-14 - Character-set library.
ispunct
Not directly supported, but you can use (char-set-contains? char-set:punctuation c) with srfi-14. See section 10.8 srfi-14 - Character-set library.
isspace
R5RS char-whitespace?. See section 6.8 Characters. You can also use (char-set-contains? char-set:whitespace c) with srfi-14. See section 10.8 srfi-14 - Character-set library.
isupper
R5RS char-upper-case?. See section 6.8 Characters. You can also use (char-set-contains? char-set:upper-case c) with srfi-14. See section 10.8 srfi-14 - Character-set library.
isxdigit
Not directly supported, but you can use (char-set-contains? char-set:hex-digit c) with srfi-14. See section 10.8 srfi-14 - Character-set library.
kill
Gauche's sys-kill. See section 6.21.6 Signal.
labs
R5RS abs. See section 6.2.4 Arithmetics.
ldexp
Gauche's ldexp.
ldiv
Use R5RS quotient and remainder. See section 6.2.4 Arithmetics.
link
Gauche's sys-link. See section 6.21.3.2 Directory manipulation.
localeconv
Gauche's sys-localeconv. See section 6.21.5 Locale.
localtime
Gauche's sys-localtime. See section 6.21.8 Time.
log
R5RS log. See section 6.2.4 Arithmetics.
log10
Not directly supported. log10(z) == (/ (log z) (log 10)).
longjmp
R5RS call/cc provides similar (superior) mechanism. See section 6.15.3 Continuation.
lseek
Not supported yet.
malloc
Not necessary in Scheme.
mblen
mbstowcs
mbtowc
Gauche handles multibyte strings internally, so generally you don't need to care about multibyte-ness of the string. string-length always returns a number of characters for a string in supported encoding. If you want to convert the character encoding, see 9.2 gauche.charconv - Character Code Conversion.
memcmp
memcpy
memmove
memset
No equivalent functions.
mkdir
Gauche's sys-mkdir. See section 6.21.3.2 Directory manipulation.
mkfifo
Gauche's sys-mkfifo.
mkstemp
Gauche's sys-mkstemp. See section 6.21.3.2 Directory manipulation. Use this instead of tmpnam.
mktime
Gauche's sys-mktime. See section 6.21.8 Time.
modf
Gauche's modf.
open
Not directly supported. R5RS open-input-file or open-output-file corresponds to this operation. See section 6.18.3 File ports.
opendir
Not directly supported. You can use sys-readdir to read the directory entries at once. See section 6.21.3.1 Directories.
openpty
Use sys-openpty. See section 9.20 gauche.termios - Termios.
pathconf
Not supported.
pause
Gauche's sys-pause. See section 6.21.11 Miscellaneous system calls.
perror
No equivalent function in Gauche. System calls generally throws an error (<system-error>), including the description of the reason of failure.
pipe
Gauche's sys-pipe. See section 6.21.3.5 Other file operations.
pow
R5RS expt. See section 6.2.4 Arithmetics.
printf
Not directly supported, but Gauche's format provides similar functionality. See section 6.18.7 Output. SLIB has printf implementation.
putc
putchar
Use write-char or write-byte. See section 6.18.7 Output.
puts
Use display. See section 6.18.7 Output.
qsort
Gauche's sort and sort! provides a convenient way to sort list of items. See section 6.20 Comparison and sorting.
raise
No equivalent function in Gauche. Scheme function raise (SRFI-18) is to raise an exception. You can use (sys-kill (sys-getpid) SIG) to send a signal SIG to the current process.
rand
Not supported directly, but on most platforms a better RNG is available as sys-random. See section 6.21.11 Miscellaneous system calls.
read
Not supported directly, but you may be able to use read-block (See section 6.18.6 Input) or read-block! (See section 9.24.4 Uvector block I/O).
readdir
Not supported directly. Gauche's sys-readdir reads the directly at once. See section 6.21.3.1 Directories.
readlink
Gauche's sys-readlink. See section 6.21.3.2 Directory manipulation. This function is available on systems that support symbolink links.
realloc
Not necessary in Scheme.
remove
Gauche's sys-remove. See section 6.21.3.2 Directory manipulation.
rename
Gauche's sys-rename. See section 6.21.3.2 Directory manipulation.
rewind
Not supported yet.
rewinddir
Not supported directly. You can use sys-readdir to read the directory entries at once. See section 6.21.3.1 Directories.
rmdir
Gauche's sys-rmdir. See section 6.21.3.2 Directory manipulation.
scanf
Not supported. For general case, you have to write a parser. If you can keep the data in S-exp, you can use read. If the syntax is very simple, you may be able to utilize string-tokenize in srfi-14 (10.7 srfi-13 - String library), and/or regular expression stuff (6.11 Regular expression, also 9.15 gauche.regexp - Regular expression utilities.
select
Gauche sys-select. See section 6.21.10 I/O multiplexing.
setbuf
Not necessary.
setgid
Gauche's sys-setgid.
setjmp
R5RS call/cc provides similar (superior) mechanism. See section 6.15.3 Continuation.
setlocale
Gauche's sys-setlocale. See section 6.21.5 Locale.
setpgid
Gauche's sys-setpgid. See section 6.21.7 System Inquiry.
setsid
Gauche's sys-setsid. See section 6.21.7 System Inquiry.
setuid
Gauche's sys-setuid. See section 6.21.7 System Inquiry.
setvbuf
Not necessary.
sigaction
You can use with-signal-handlers to install signal handlers. See section 6.21.6.3 Handling signals.
sigaddset
sigdelset
sigemptyset
sigfillset
Gauche's sys-sigset-add! and sys-sigset-delete!. See section 6.21.6.1 Signals and signal sets.
sigismember
Not supported yet.
siglongjmp
R5RS call/cc provides similar (superior) mechanism. See section 6.15.3 Continuation.
signal
You can use with-signal-handlers to install signal handlers. See section 6.21.6.3 Handling signals.
sigpending
Not supported yet.
sigprocmask
Signal mask is handled internally. See See section 6.21.6.3 Handling signals.
sigsetjmp
R5RS call/cc provides similar (superior) mechanism. See section 6.15.3 Continuation.
sigsuspend
Not supported yet.
sin
sinh
Use sin and sinh. See section 6.2.4 Arithmetics.
sleep
Gauche's sys-sleep. See section 6.21.11 Miscellaneous system calls.
sprintf
Not directly supported, but Gauche's format provides similar functionality. See section 6.18.7 Output. SLIB has printf implementation.
sqrt
R5RS sqrt. See section 6.2.4 Arithmetics.
srand
Not supported directly, but on most platforms a better RNG is available as sys-srandom. See section 6.21.11 Miscellaneous system calls.
sscanf
Not supported. For general case, you have to write a parser. If you can keep the data in S-exp, you can use read. If the syntax is very simple, you may be able to utilize string-tokenize in srfi-14 (10.7 srfi-13 - String library), and/or regular expression stuff (6.11 Regular expression, also 9.15 gauche.regexp - Regular expression utilities.
stat
Gauche's sys-stat. See section 6.21.3.4 File stats.
strcasecmp
R5RS string-ci=? and other comparison functions. See section 6.10.6 String Comparison.
strcat
R5RS string-append. See section 6.10.7 String utilities.
strchr
SRFI-13 string-index. See section 10.7.7 String searching.
strcmp
R5RS string=? and other comparison functions. See section 6.10.6 String Comparison.
strcoll
Not supported yet.
strcpy
R5RS string-copy. See section 6.10.7 String utilities.
strcspn
Not directly supported, but you can use SRFI-13 string-skip with a character set. See section 10.7.7 String searching.
strerror
Not supported.
strftime
Gauche's sys-strftime. See section 6.21.8 Time.
strlen
R5RS string-length. See section 6.10.5 String Accessors & Modifiers.
strncat
Not directly supported, but you can use string-append and substring.
strncasecmp
SRFI-13 string-compare-ci provides the most flexible (but a bit difficult to use) functionality. See section 10.7.5 String comparison. If what you want is just to check the fixed-length prefixes of two string matches, you can use SRFI-13 string-prefix-ci?.
strncmp
SRFI-13 string-compare provides the most flexible (but a bit difficult to use) functionality. See section 10.7.5 String comparison. If what you want is just to check the fixed-length prefixes of two string matches, you can use SRFI-13 string-prefix?. See section 10.7.6 String Prefixes & Suffixes.
strncpy
SRFI-13 substring. See section 6.10.7 String utilities.
strpbrk
Not directly supported, but you can use SRFI-13 string-skip with a character set. See section 10.7.7 String searching.
strrchr
SRFI-13 string-index-right. See section 10.7.7 String searching.
strspn
Not directly supported, but you can use SRFI-13 string-index with a character set. See section 10.7.7 String searching.
strstr
SRFI-13 string-contains. See section 10.7.7 String searching.
strtod
You can use R5RS string->number. See section 6.2.5 Numerical conversions.
strtok
SRFI-13 string-tokenize. See section 10.7.12 Other string operations.
strtol
strtoul
You can use R5RS string->number. See section 6.2.5 Numerical conversions.
strxfrm
Not supported yet.
symlink
Gauche's sys-symlink. See section 6.21.3.2 Directory manipulation. This function is available on systems that support symbolink links.
sysconf
Not supported yet.
system
Gauche sys-system. See section 6.21.9.1 Fork and exec. It is generally recommended to use the process library (9.14 gauche.process - High Level Process Interface).
tan
tanh
R5RS tan and Gauche tanh. See section 6.2.4 Arithmetics.
tcdrain
tcflow
tcflush
tcgetattr
tcgetpgrp
tcsendbreak
tcsetattr
tcsetpgrp
Corresponding functions are: sys-tcdrain, sys-tcflow, sys-tcflush, sys-tcgetattr, sys-tcgetpgrp, sys-tcsendbreak, sys-tcsetattr, sys-tcsetpgrp. See section 9.20 gauche.termios - Termios
time
Gauche's sys-time. See section 6.21.8 Time.
times
Gauche's sys-times. See section 6.21.7 System Inquiry.
tmpfile
Not exactly supported.
tmpnam
Gauche's sys-tmpnam. This function is provided since it is in POSIX, but its use is discouraged for the potential security risk. Use sys-mkstemp instead. See section 6.21.3.2 Directory manipulation.
tolower
toupper
R5RS char-upcase and char-downcase. See section 6.8 Characters.
ttyname
Gauche's sys-ttyname. See section 6.21.3.5 Other file operations.
tzset
Not supported yet.
umask
Gauche's sys-umask. See section 6.21.3.2 Directory manipulation.
uname
Gauche's sys-uname. See section 6.21.7 System Inquiry.
ungetc
Not directly supported. You can use peek-char to look one character ahead, instead of pushing back.
unlink
Gauche's sys-unlink. See section 6.21.3.2 Directory manipulation.
utime
Not supported yet.
va_arg
va_end
va_start
Not necessary, for Scheme handles variable number of arguments naturally.
vfprintf
vprintf
vsprintf
Not directly supported, but Gauche's format provides similar functionality. See section 6.18.7 Output. SLIB has printf implementation.
wait
Gauche's sys-wait. See section 6.21.9.2 Wait.
waitpid
Gauche's sys-waitpid. See section 6.21.9.2 Wait.
wcstombs
wctomb
Gauche handles multibyte strings internally, so generally you don't need to care about multibyte-ness of the string. string-length always returns a number of characters for a string in supported encoding. If you want to convert the character encoding, see 9.2 gauche.charconv - Character Code Conversion.
write
R5RS display (See section 6.18.7 Output). Or write-block (See section 9.24.4 Uvector block I/O).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated by Ken Dickey on November, 28 2002 using texi2html