BeSly Software Solutions About yab Demos About us Admin






Name:

import -- import a library

Synopsis:
 
import foo 

Description:
The import-statment imports a library. It expects a single argument, which must be the name of a library (without the trailing .yab). This library will then be read and parsed and its subroutines (and variables) will be made available within the main program.

Libraries will first be searched within the current directory (i.e. the directory within which you have invoked yab), then within the special directory /boot/home/config/settings/yab. The location of this second directory may be changed with the option -library.

Example:
import lib 

rem  This works ... 
lib.x(0) 

rem  This works too .. 
x(1) 

rem  And this. 
lib.y(2) 

rem  But this not! 
y(3) 
Explanation:

Lets say you have a yab-program foo.yab, which imports a library lib.yab. 
 
Now the library lib.yab reads:


rem  Make the subroutine x easily available outside this library 
export sub x(a) 
  print a 
  return 
end sub 

rem  sub y must be referenced by its full name 
rem  outside this library 
sub y(a) 
  print a 
  return 
end sub 


This program produces an error:
 

0 
1 
2 
---Error in foo.yab, line 13: can't find subroutine 'y' 
---Dump: sub y() called in foo.yab,13 
---Error: Program stopped due to an error 


As you may see from the error message, yab is unable to find the subroutine y without specifying the name of the library (i.e. lib.y). The reason for this is, that y, other than x, is not exported from the library lib.yab (using the export-statement). 



Related: export, sub