For Gauche 0.9.15Search (procedure/syntax/module):

Next: , Previous: , Up: Top   [Contents][Index]

Appendix A 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.

+

R7RS arithmetic procedure +. See Arithmetics.

+=

Gauche inc! macro. See Assignments.

-

R7RS arithmetic procedure -. See Arithmetics.

-=

Gauche dec! macro. See Assignments.

->

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

* (binary)

R7RS arithmetic procedure *. See Arithmetics.

* (unary)

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

*=

No equivalent procedure.

/

In C, it has two different meanings depending on the types of operands. For real division, use /. For integer quotient, use quotient. See Arithmetics.

/=

No equivalent procedure.

& (binary)

Gauche logand. See scheme.bitwise - R7RS bitwise operations.

& (unary)

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

&&

R7RS syntax and. See Conditionals.

&=

No equivalent procedure.

|

Gauche logior. See scheme.bitwise - R7RS bitwise operations.

||

R7RS syntax or. See Conditionals.

|=

No equivalent procedure.

^

Gauche logxor. See scheme.bitwise - R7RS bitwise operations.

=

R7RS syntax set!. See Assignments.

==

R7RS equivalence procedure, eq?, eqv? and equal?. See Equality.

<
<=

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

<<

Gauche ash. See scheme.bitwise - R7RS bitwise operations.

<<=

No equivalent procedure.

>
>=

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

>>

Gauche ash. See scheme.bitwise - R7RS bitwise operations.

>>=

No equivalent procedure.

%

R7RS operator modulo and remainder. See Arithmetics.

%=

No equivalent procedure.

[]

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

.

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

~

Gauche lognot. See scheme.bitwise - R7RS bitwise operations.

~=

No equivalent procedure.

!

R7RS procedure not. See Booleans.

!=

No equivalent procedure.

abort

Gauche sys-abort. See Program termination.

abs

R7RS abs. See Arithmetics.

access

Gauche sys-access. See File stats.

acos

R7RS acos. See Arithmetics.

alarm

Gauche sys-alarm. See Miscellaneous system calls.

asctime

Gauche sys-asctime. See Time.

asin

R7RS asin. See Arithmetics.

assert

No equivalent function in Gauche.

atan
atan2

R7RS atan. See Arithmetics.

atexit

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

atof
atoi
atol

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

bsearch

You can use SRFI-133’s vector-binary-search. See scheme.vector - R7RS vectors.

calloc

Allocation is handled automatically in Scheme.

ceil

R7RS ceiling. See Arithmetics.

cfgetispeed
cfgetospeed
cfsetispeed
cfsetospeed

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

chdir

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

chmod

Gauche’s sys-chmod. See File stats.

chown

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

closedir

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

cos
cosh

cos and cosh. See Arithmetics.

creat

A file is implicitly 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 System inquiry.

ctime

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

div

You can use R7RS quotient and remainder. See Arithmetics.

dup
dup2

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

execl
execle
execlp
execv
execve
execvp

Gauche sys-exec. See 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 Program termination.

exp

R7RS exp. See Arithmetics.

fabs

R7RS abs. See 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 gauche.fcntl - Low-level file operations.

fdopen

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

feof

No equivalent operation, but you can check if an input port have reached to the end by peek-char or peek-byte. See Reading data.

ferror

Not supported yet.

fflush

Gauche’s flush. See Output.

fgetc

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

fgetpos

Use Gauche’s port-tell (see Common port operations)

fgets

Use read-line or read-string. See Input.

fileno

port-file-number. See Common port operations.

floor

R7RS floor. See Arithmetics.

fmod

Gauche’s fmod.

fopen

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

fork

Gauche’s sys-fork. See Process management.

forkpty

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

fpathconf

Not supported.

fprintf

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

fputc

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

fputs

Use display. See 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-uvector!. See 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 Common port operations)

fsetpos

Use Gauche’s port-seek (see Common port operations)

fstat

Gauche’s sys-stat. See File stats.

ftell

Use Gauche’s port-tell (see 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-uvector (see Uvector block I/O).

getc
getchar

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

getcwd

Gauche’s sys-getcwd. See System inquiry.

getdomainname

Gauche’s sys-getdomainname. See System inquiry.

getegid

Gauche’s sys-getegid. See System inquiry.

getenv

Gauche’s sys-getenv. See Environment inquiry.

geteuid

Gauche’s sys-geteuid. See System inquiry.

gethostname

Gauche’s sys-gethostname. See System inquiry.

getgid

Gauche’s sys-getgid. See System inquiry.

getgrgid
getgrnam

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

getgroups

Gauche’s sys-getgroups. See System inquiry.

getlogin

Gauche’s sys-getlogin. See System inquiry.

getpgrp

Gauche’s sys-getpgrp. See System inquiry.

getpid
getppid

Gauche’s sys-getpid. See System inquiry.

getpwnam
getpwuid

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

gets

Use read-line or read-string. See Input.

gettimeofday

Gauche’s sys-gettimeofday. See Time.

getuid

Gauche’s sys-getuid. See System inquiry.

gmtime

Gauche’s sys-gmtime. See Time.

isalnum

Not directly supported, but you can use R7RS char-alphabetic? and char-numeric?. See Characters. You can also use character set. See Character Sets, also scheme.charset - R7RS character sets.

isalpha

R7RS char-alphabetic?. See Characters. See also Character Sets and scheme.charset - R7RS character sets.

isatty

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

iscntrl

Not directly supported, but you can use (char-set-contains? char-set:iso-control c) with srfi.14. See scheme.charset - R7RS character sets.

isdigit

R7RS char-numeric?. See Characters. You can also use (char-set-contains? char-set:digit c) with srfi.14. See scheme.charset - R7RS character sets.

isgraph

Not directly supported, but you can use (char-set-contains? char-set:graphic c) with srfi.14. See scheme.charset - R7RS character sets.

islower

R7RS char-lower-case?. See Characters. You can also use (char-set-contains? char-set:lower-case c) with srfi.14. See scheme.charset - R7RS character sets.

isprint

Not directly supported, but you can use (char-set-contains? char-set:printing c) with srfi.14. See scheme.charset - R7RS character sets.

ispunct

Not directly supported, but you can use (char-set-contains? char-set:punctuation c) with srfi.14. See scheme.charset - R7RS character sets.

isspace

R7RS char-whitespace?. See Characters. You can also use (char-set-contains? char-set:whitespace c) with srfi.14. See scheme.charset - R7RS character sets.

isupper

R7RS char-upper-case?. See Characters. You can also use (char-set-contains? char-set:upper-case c) with srfi.14. See scheme.charset - R7RS character sets.

isxdigit

Not directly supported, but you can use (char-set-contains? char-set:hex-digit c) with srfi.14. See scheme.charset - R7RS character sets.

kill

Gauche’s sys-kill. See Signal.

labs

R7RS abs. See Arithmetics.

ldexp

Gauche’s ldexp.

ldiv

Use R7RS quotient and remainder. See Arithmetics.

link

Gauche’s sys-link. See Directory manipulation.

localeconv

Gauche’s sys-localeconv. See Locale.

localtime

Gauche’s sys-localtime. See Time.

log

R7RS log. See Arithmetics.

log10

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

longjmp

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

lseek

Use Gauche’s port-seek (see 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 Directory manipulation.

mkfifo

Gauche’s sys-mkfifo.

mkstemp

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

mktime

Gauche’s sys-mktime. See Time.

modf

Gauche’s modf.

open

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

opendir

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

openpty

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

pathconf

Not supported.

pause

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

pow

R7RS expt. See Arithmetics.

printf

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

putc
putchar

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

puts

Use display. See Output.

qsort

Gauche’s sort and sort! provides a convenient way to sort list of items. See Sorting and merging.

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 Miscellaneous system calls.

read

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

readdir

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

readlink

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

realloc

Not necessary in Scheme.

realpath

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

remove

Gauche’s sys-remove. See Directory manipulation.

rename

Gauche’s sys-rename. See Directory manipulation.

rewind

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

rewinddir

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

rmdir

Gauche’s sys-rmdir. See 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 I/O multiplexing.

setbuf

Not necessary.

setgid

Gauche’s sys-setgid.

setjmp

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

setlocale

Gauche’s sys-setlocale. See Locale.

setpgid

Gauche’s sys-setpgid. See System inquiry.

setsid

Gauche’s sys-setsid. See System inquiry.

setuid

Gauche’s sys-setuid. See System inquiry.

setvbuf

Not necessary.

sigaction

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

sigaddset
sigdelset
sigemptyset
sigfillset

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

sigismember

Not supported yet.

siglongjmp

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

signal

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

sigpending

Not supported yet.

sigprocmask

Signal mask is handled internally. See Handling signals.

sigsetjmp

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

sigsuspend

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

sigwait

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

sin
sinh

Use sin and sinh. See Arithmetics.

sleep

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

sprintf

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

sqrt

R7RS sqrt. See Arithmetics.

srand

Not supported directly, but on most platforms a better RNG is available as sys-srandom (see Miscellaneous system calls). The math.mt-random module provides much superior RNG (see 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 File stats.

strcasecmp

R7RS string-ci=? and other comparison functions. See String comparison.

strcat

R7RS string-append. See String utilities.

strchr

SRFI-13 string-index. See String searching.

strcmp

R7RS string=? and other comparison functions. See String comparison.

strcoll

Not supported yet.

strcpy

R7RS string-copy. See String utilities.

strcspn

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

strerror

Gauche’s sys-strerror. See System inquiry.

strftime

Gauche’s sys-strftime. See Time.

strlen

R7RS string-length. See 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 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 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 String prefixes & suffixes.

strncpy

SRFI-13 substring. See String utilities.

strpbrk

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

strrchr

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

strspn

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

strstr

SRFI-13 string-contains. See String searching.

strtod

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

strtok

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

strtol
strtoul

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

strxfrm

Not supported yet.

symlink

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

sysconf

Not supported yet.

system

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

tan
tanh

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

time

Gauche’s sys-time. See Time.

times

Gauche’s sys-times. See System inquiry.

tmpfile

Not exactly supported. See sys-mkstemp instead. See Directory manipulation.

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 Directory manipulation.

tolower
toupper

R7RS char-upcase and char-downcase. See Characters.

ttyname

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

tzset

Not supported yet.

umask

Gauche’s sys-umask. See Directory manipulation.

uname

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

utime

Gauche’s sys-utime. See 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 Output. SLIB has printf implementation.

wait

Gauche’s sys-wait. See Process management.

waitpid

Gauche’s sys-waitpid. See 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

R7RS display (see Output). Or write-uvector (see Uvector block I/O).


Next: , Previous: , Up: Top   [Contents][Index]


For Gauche 0.9.15Search (procedure/syntax/module):