[ < ] [ > ]   [ << ] [ 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 Arithmetics.

+=

Gauche inc! macro. See section Assignments.

-

R5RS arithmetic procedure -. See section Arithmetics.

-=

Gauche dec! macro. See section Assignments.

->

Gauche slot-ref is something close to this. See section Accessing instance.

* (binary)

R5RS arithmetic procedure *. See section Arithmetics.

* (unary)

No equivalent procedure. Scheme doesn’t have explicit notation of pointers.

*=

No equivalent procedure.

/

R5RS arithmetic procedure /. See section Arithmetics.

/=

No equivalent procedure.

& (binary)

Gauche logand. See section Bitwise operations.

& (unary)

No equivalent procedure. Scheme doesn’t have explicit notation of pointers.

&&

R5RS syntax and. See section Conditionals.

&=

No equivalent procedure.

|

Gauche logior. See section Bitwise operations.

||

R5RS syntax or. See section Conditionals.

|=

No equivalent procedure.

^

Gauche logxor. See section Bitwise operations.

=

R5RS syntax set!. See section Assignments.

==

R5RS equivalence procedure, eq?, eqv? and equal?. See section Equivalence.

<
<=

R5RS arithmetic procedure < and <=. See section Numerical comparison. Unlike C operator, Scheme version is transitive.

<<

Gauche ash. See section Bitwise operations.

<<=

No equivalent procedure.

>
>=

R5RS arithmetic procedure > and >=. See section Numerical comparison. Unlike C operator, Scheme version is transitive.

>>

Gauche ash. See section Bitwise operations.

>>=

No equivalent procedure.

%

R5RS operator modulo and remainder. See section Arithmetics.

%=

No equivalent procedure.

[]

R5RS vector-ref (See section Vectors) is something close. Or you can use Gauche’s generic function ref (See section gauche.sequence - Sequence framework) for arbitrary sequences.

.

Gauche slot-ref is something close to this. See section Accessing instance.

~

Gauche lognot. See section Bitwise operations.

~=

No equivalent procedure.

!

R5RS procedure not. See section Booleans.

!=

No equivalent procedure.

abort

Gauche sys-abort. See section Program termination.

abs

R5RS abs. See section Arithmetics.

access

Gauche sys-access. See section File stats.

acos

R5RS acos. See section Arithmetics.

alarm

Gauche sys-alarm. See section Miscellaneous system calls.

asctime

Gauche sys-asctime. See section Time.

asin

R5RS asin. See section Arithmetics.

assert

No equivalent function in Gauche.

atan
atan2

R5RS atan. See section Arithmetics.

atexit

No equivalent function in Gauche, but the "after" thunk of active dynamic handlers are called when exit is called. See section Program termination, and See section Continuations.

atof
atoi
atol

You can use string->number. See section Numerical conversions.

bsearch

You can use SRFI-43’s vector-binary-search. See section srfi-43 - Vector library.

calloc

Allocation is handled automatically in Scheme.

ceil

R5RS ceiling. See section Arithmetics.

cfgetispeed
cfgetospeed
cfsetispeed
cfsetospeed

Gauche’s sys-cfgetispeed, sys-cfgetospeed, sys-cfsetispeed, sys-cfsetospeed. See section gauche.termios - Terminal control.

chdir

Gauche’s sys-chdir. See section Other file operations.

chmod

Gauche’s sys-chmod. See section File stats.

chown

Gauche’s sys-chown. See section 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 Common port operations.

closedir

No equivalent function in Gauche. You can use sys-readdir to read the directory entries at once. See section Directories.

cos
cosh

cos and cosh. See section Arithmetics.

creat

A file is implictly created by default when you open it for writing. See File ports for more control over the creation of files.

ctermid

Gauche sys-ctermid. See section System inquiry.

ctime

Gauche sys-ctime. See section 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 Time.

div

You can use R5RS quotient and remainder. See section Arithmetics.

dup
dup2

Not directly supported, but you can use port-fd-dup!.

execl
execle
execlp
execv
execve
execvp

Gauche sys-exec. See section Process management. For higher level interface, gauche.process - High Level Process Interface.

exit
_exit

Use exit or sys-exit, depends on what you need. See section Program termination.

exp

R5RS exp. See section Arithmetics.

fabs

R5RS abs. See section 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

Implemented as sys-fcntl in gauche.fcntl module. See section gauche.fcntl - Low-level file operations.

fdopen

Gauche’s open-input-fd-port or open-output-fd-port. See section File ports.

feof

Not supported yet.

ferror

Not supported yet.

fflush

Gauche’s flush. See section Output.

fgetc

Use read-char or read-byte. See section Input.

fgetpos

Use Gauche’s port-tell (See section Common port operations)

fgets

Use read-line or read-block. See section Input.

fileno

port-file-numer. See section Common port operations.

floor

R5RS floor. See section Arithmetics.

fmod

Gauche’s fmod.

fopen

R5RS open-input-file or open-output-file corresponds to this operation. See section File ports.

fork

Gauche’s sys-fork. See section Process management.

forkpty

Use sys-forkpty. See section gauche.termios - Terminal control.

fpathconf

Not supported.

fprintf

Not directly supported, but Gauche’s format provides similar functionality. See section Output. SLIB has printf implementation.

fputc

Use write-char or write-byte. See section Output.

fputs

Use display. See section Output.

fread

Not directly supported. To read binary numbers, see binary.io - Binary I/O. If you want to read a chunk of bytes, you may be able to use read-block!. See section Uvector block I/O.

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 (srfi-13 - String library), and/or regular expression stuff (Regular expressions).

fseek

Use Gauche’s port-seek (See section Common port operations)

fsetpos

Use Gauche’s port-seek (See section Common port operations)

fstat

Gauche’s sys-stat. See section File stats.

ftell

Use Gauche’s port-tell (See section Common port operations)

fwrite

Not directly supported. To write binary numbers, see binary.io - Binary I/O. If you want to write a chunk of bytes, you can simply use display or write-block (See section Uvector block I/O).

getc
getchar

Use read-char or read-byte. See section Input.

getcwd

Gauche’s sys-getcwd. See section System inquiry.

getdomainname

Gauche’s sys-getdomainname. See section System inquiry.

getegid

Gauche’s sys-getegid. See section System inquiry.

getenv

Gauche’s sys-getenv. See section Environment Inquiry.

geteuid

Gauche’s sys-geteuid. See section System inquiry.

gethostname

Gauche’s sys-gethostname. See section System inquiry.

getgid

Gauche’s sys-getgid. See section System inquiry.

getgrgid
getgrnam

Gauche’s sys-getgrgid and sys-getgrnam. See section Unix groups and users.

getgroups

Gauche’s sys-getgroups. See section System inquiry.

getlogin

Gauche’s sys-getlogin. See section System inquiry.

getpgrp

Gauche’s sys-getpgrp. See section System inquiry.

getpid
getppid

Gauche’s sys-getpid. See section System inquiry.

getpwnam
getpwuid

Gauche’s sys-getpwnam and sys-getpwuid. See section Unix groups and users.

gets

Use read-line or read-block. See section Input.

gettimeofday

Gauche’s sys-gettimeofday. See section Time.

getuid

Gauche’s sys-getuid. See section System inquiry.

gmtime

Gauche’s sys-gmtime. See section Time.

isalnum

Not directly supported, but you can use R5RS char-alphabetic? and char-numeric?. See section Characters. You can also use character set. See section Character Set, also srfi-14 - Character-set library.

isalpha

R5RS char-alphabetic?. See section Characters. See also Character Set and srfi-14 - Character-set library.

isatty

Gauche’s sys-isatty. See section Other file operations.

iscntrl

Not directly supported, but you can use (char-set-contains? char-set:iso-control c) with srfi-14. See section srfi-14 - Character-set library.

isdigit

R5RS char-numeric?. See section Characters. You can also use (char-set-contains? char-set:digit c) with srfi-14. See section 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 srfi-14 - Character-set library.

islower

R5RS char-lower-case?. See section Characters. You can also use (char-set-contains? char-set:lower-case c) with srfi-14. See section 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 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 srfi-14 - Character-set library.

isspace

R5RS char-whitespace?. See section Characters. You can also use (char-set-contains? char-set:whitespace c) with srfi-14. See section srfi-14 - Character-set library.

isupper

R5RS char-upper-case?. See section Characters. You can also use (char-set-contains? char-set:upper-case c) with srfi-14. See section 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 srfi-14 - Character-set library.

kill

Gauche’s sys-kill. See section Signal.

labs

R5RS abs. See section Arithmetics.

ldexp

Gauche’s ldexp.

ldiv

Use R5RS quotient and remainder. See section Arithmetics.

link

Gauche’s sys-link. See section Directory manipulation.

localeconv

Gauche’s sys-localeconv. See section Locale.

localtime

Gauche’s sys-localtime. See section Time.

log

R5RS log. See section Arithmetics.

log10

Not directly supported. log10(z)(/ (log z) (log 10)).

longjmp

R5RS call/cc provides similar (superior) mechanism. See section Continuations.

lseek

Use Gauche’s port-seek (See section Common port operations)

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 gauche.charconv - Character Code Conversion.

memcmp
memcpy
memmove
memset

No equivalent functions.

mkdir

Gauche’s sys-mkdir. See section Directory manipulation.

mkfifo

Gauche’s sys-mkfifo.

mkstemp

Gauche’s sys-mkstemp. See section Directory manipulation. Use this instead of tmpnam.

mktime

Gauche’s sys-mktime. See section Time.

modf

Gauche’s modf.

open

Not directly supported. R5RS open-input-file or open-output-file corresponds to this operation. See section File ports.

opendir

Not directly supported. You can use sys-readdir to read the directory entries at once. See section Directories.

openpty

Use sys-openpty. See section gauche.termios - Terminal control.

pathconf

Not supported.

pause

Gauche’s sys-pause. See section 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 Other file operations.

pow

R5RS expt. See section Arithmetics.

printf

Not directly supported, but Gauche’s format provides similar functionality. See section Output. SLIB has printf implementation.

putc
putchar

Use write-char or write-byte. See section Output.

puts

Use display. See section Output.

qsort

Gauche’s sort and sort! provides a convenient way to sort list of items. See section 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 Miscellaneous system calls.

read

Not supported directly, but you may be able to use read-block (See section Input) or read-block! (See section Uvector block I/O).

readdir

Not supported directly. Gauche’s sys-readdir reads the directory at once. See section Directories.

readlink

Gauche’s sys-readlink. See section Directory manipulation. This function is available on systems that support symbolink links.

realloc

Not necessary in Scheme.

realpath

Gauche’s sys-normalize-pathname or sys-realpath. See section Pathnames.

remove

Gauche’s sys-remove. See section Directory manipulation.

rename

Gauche’s sys-rename. See section Directory manipulation.

rewind

Not directly supported, but you can use port-seek instead. See section Common port operations.

rewinddir

Not supported directly. You can use sys-readdir to read the directory entries at once. See section Directories.

rmdir

Gauche’s sys-rmdir. See section 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 (srfi-13 - String library), and/or regular expression stuff (Regular expressions).

select

Gauche’s sys-select. See section I/O multiplexing.

setbuf

Not necessary.

setgid

Gauche’s sys-setgid.

setjmp

R5RS call/cc provides similar (superior) mechanism. See section Continuations.

setlocale

Gauche’s sys-setlocale. See section Locale.

setpgid

Gauche’s sys-setpgid. See section System inquiry.

setsid

Gauche’s sys-setsid. See section System inquiry.

setuid

Gauche’s sys-setuid. See section System inquiry.

setvbuf

Not necessary.

sigaction

You can use set-signal-handler! to install signal handlers. See section Handling signals.

sigaddset
sigdelset
sigemptyset
sigfillset

Gauche’s sys-sigset-add! and sys-sigset-delete!. See section Signals and signal sets.

sigismember

Not supported yet.

siglongjmp

R5RS call/cc provides similar (superior) mechanism. See section Continuations.

signal

You can use with-signal-handlers to install signal handlers. See section Handling signals.

sigpending

Not supported yet.

sigprocmask

Signal mask is handled internally. See section Handling signals.

sigsetjmp

R5RS call/cc provides similar (superior) mechanism. See section Continuations.

sigsuspend

Gauche’s sys-sigsuspend. See section Masking and waiting signals.

sigwait

Gauche’s sys-sigwait. See section Masking and waiting signals.

sin
sinh

Use sin and sinh. See section Arithmetics.

sleep

Gauche’s sys-sleep. See section Miscellaneous system calls.

sprintf

Not directly supported, but Gauche’s format provides similar functionality. See section Output. SLIB has printf implementation.

sqrt

R5RS sqrt. See section Arithmetics.

srand

Not supported directly, but on most platforms a better RNG is available as sys-srandom (See section Miscellaneous system calls). The math.mt-random module provides much superior RNG (See section math.mt-random - Mersenne Twister Random number generator).

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 (srfi-13 - String library), and/or regular expression stuff (Regular expressions).

stat

Gauche’s sys-stat. See section File stats.

strcasecmp

R5RS string-ci=? and other comparison functions. See section String Comparison.

strcat

R5RS string-append. See section String utilities.

strchr

SRFI-13 string-index. See section String searching.

strcmp

R5RS string=? and other comparison functions. See section String Comparison.

strcoll

Not supported yet.

strcpy

R5RS string-copy. See section String utilities.

strcspn

Not directly supported, but you can use SRFI-13 string-skip with a character set. See section String searching.

strerror

Gauche’s sys-strerror. See section System inquiry.

strftime

Gauche’s sys-strftime. See section Time.

strlen

R5RS string-length. See section 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 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 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 String Prefixes & Suffixes.

strncpy

SRFI-13 substring. See section String utilities.

strpbrk

Not directly supported, but you can use SRFI-13 string-skip with a character set. See section String searching.

strrchr

SRFI-13 string-index-right. See section String searching.

strspn

Not directly supported, but you can use SRFI-13 string-index with a character set. See section String searching.

strstr

SRFI-13 string-contains. See section String searching.

strtod

You can use R5RS string->number. See section Numerical conversions.

strtok

SRFI-13 string-tokenize. See section Other string operations.

strtol
strtoul

You can use R5RS string->number. See section Numerical conversions.

strxfrm

Not supported yet.

symlink

Gauche’s sys-symlink. See section Directory manipulation. This function is available on systems that support symbolink links.

sysconf

Not supported yet.

system

Gauche’s sys-system. See section Process management. It is generally recommended to use the process library (gauche.process - High Level Process Interface).

tan
tanh

R5RS tan and Gauche tanh. See section 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 gauche.termios - Terminal control

time

Gauche’s sys-time. See section Time.

times

Gauche’s sys-times. See section 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 Directory manipulation.

tolower
toupper

R5RS char-upcase and char-downcase. See section Characters.

ttyname

Gauche’s sys-ttyname. See section Other file operations.

tzset

Not supported yet.

umask

Gauche’s sys-umask. See section Directory manipulation.

uname

Gauche’s sys-uname. See section 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 Directory manipulation.

utime

Gauche’s sys-utime. See section File stats.

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 Output. SLIB has printf implementation.

wait

Gauche’s sys-wait. See section Process management.

waitpid

Gauche’s sys-waitpid. See section Process management.

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 gauche.charconv - Character Code Conversion.

write

R5RS display (See section Output). Or write-block (See section Uvector block I/O).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]

This document was generated by Shiro Kawai on May 28, 2012 using texi2html 1.82.