(read port) returns next object parsable from the given input port port.returned.If end of file is reached, eof is(read-char port) returns next character, updating port to point to the next character.(peek-char port) returns next character, <strong>with</strong>out updating port.(eof-object?obj) tests if obj is a end-of-file object.(define out (open-output-file "filename.txt"))(display (+ 3 4) out)(newline out)(close-output-port out)The first line opens an output port <strong>with</strong> name filename.txt. The file is created if it does not exist. The result of(+ 3 4) is written to the file followed by a newline. The port is closed.4.4 Useful macros(for (i from to step) (begin body )) runs a for loop from to "!# <strong>with</strong> increment step.4.5 Defining new scheme functions(define (count param1)(for (i 1 (+ param1 1))(display-l i " n")))Here we define a scheme function <strong>with</strong> name count <strong>with</strong> one argument that displays on the shell the numbers from0 to param1 separated by a newline. begin starts the body of the function. for is a macro (see useful macros).display-l displays the printable version of objects to the shell.(count 100) This is the call of the newly defined function. It displays the numbers up to 100.(define (sumupto param1)(let ((sum 0))(for (i 0 (+ param1 1))(set! sum (+ sum i)))sum))Here we define a scheme function that sums all integers up to param1. let defines <strong>and</strong> initialises local variables.set! assigns new values to a variable. A scheme function always returns the value of its last statement. Writing thelocal variable name in the last line, means that its value is returned by the function. After the comm<strong>and</strong> (definesum (sumupto 10)) sum holds 55. If the last line is omitted, the call (sumupto 10) returns nothing.5 Functions written in C++5.1 Help functions(help-classes) displays all loaded classes. To access a particular class, you type (help num) <strong>with</strong> numreferring to the class that you are interested in. If the class that you are interested in is not in the list, you need to loadthe module <strong>with</strong> a (require ’modMissingModule).(help num) displays information about the item number num in the previously displayed list.If (help num) gives you a default message currently defined as function of 0 or more6
arguments, try (help ClassName FunctionName)./usr/local/include/PrimaVision/.If still not satisfied, look in the header files(help ClassName) displays all member functions of the class ClassName.(help ClassName FunctionName) displays information about the function FunctionName of theclass ClassName.(a-propos name) lists all functions, global variables <strong>and</strong> classes that contain the string name in theirname. This function is useful when you do not remember the exact name of a function.5.2 Interaction <strong>with</strong> imagesSee also example file point.scm (section 9).(require ’modModuleName) loads the module ModuleName. It must be a compiled module. Therequire call loads the modules located in the directories of *module-path*. The st<strong>and</strong>ard PrimaVisionmodules are modArray, modArrayBitmap, modArrayMatrix, modBitmap, modColorEncode,modFilter, modGeom2D, modList, modListBitmap, modeListGeom2D, modListMatrix,modMatrix, modRegionVS, modTGFilter. You should find the corresponding modName.x.scm <strong>and</strong>modName.so in/usr/local/lib/Ravi/Site-Module.The *module-path* <strong>and</strong> the *ld-path* are set in /.ravi2/paths.scm.(load "test") or (load "test.scm") With the load comm<strong>and</strong> local test scripts can be loaded.The directories specified by *ld-path* are searched. File name extensions: <strong>Scheme</strong> files should have extension.scm. The load comm<strong>and</strong> will first look for several extensions.(define img (new TBitmapABGR 256 128)) the new function calls the constructor of the correspondingc++ class <strong>and</strong> returns a pointer to the object. The object is referenced.Deleting objects under scheme is not necessary. <strong>Scheme</strong> has automatic memory management. C++ objectsare deleted automatically by the garbage collector when the reference counter is zero. The garbage collector isautomatically called from time to time.(garbage) calls the garbage collector. This is only necessary when very large data structures are manipulated<strong>and</strong> you risk to run out of memory before the garbage collector is called automatically.(define img (new-ppm "filename.ppm"))This loads an image from a filename. Typing the variable name <strong>with</strong>out parentheses displays information about thevariable. This is a way to test if the loading is successful.(send img GetPixelFloat i j) The send function ”sends” a method call to a c++ object.the way to execute c++ class methods. (The GetPixelFloat method returns the pixel at position (i, j).This is(send img SetPixel value i j b<strong>and</strong>) The channel b<strong>and</strong> of pixel (i,j) of img is set to value.The order of the color b<strong>and</strong>s can be machine dependent.(send img GetRedImage) returns the red byte image of a multi-b<strong>and</strong> image, independent of the machine.(define float img (send img Convert kFloat)) converts the image of type TBitmapByte, TBitmapABGR,or TBitmapRGB to TBitmapFloat.7