Built-in Libraries and Types, Modules, and XSB predicates

We have already encountered some built-in types, like \date and \boolean. Flora also has a number of built-in operations on these types. The full list of built-in types and the operations on them can be found in the chapter “Primitive Data Types” in the Flora-2 manual [1]. It is worthwhile to familiarize yourself with this chapter. For example, to get the year component out of a \date object, one can do:

?date[ year -> ?year ]@\basetype

The @ operator tells Flora that the property is defined in a module, whose name follows the @. All operations on the built-in types are found in the \basetype module. The @module syntax should follow directly after the frame.

All Flora content is contained in a module. A module is a runtime or in-memory notion; not a file-based notion. A file (or statement) can be loaded into different modules at runtime. By default, the “main” module is used. It is possible for a user to define other modules. We have generally found this to be more problematic than useful, and module support is not heavily tested in Sunflower. We recommend not defining your own modules, and thus only using the @ syntax to call pre-defined modules.

Besides the \basetype module, two other modules are good to know about: \io and \prolog.

The \io module, as its name implies, allows you to do to certain I/O operations. One common use of it is to print text to the console, as debugging statements inside rules. For example,

?Person [ thirdCousin -> ?ThirdCousin ] :-
  ?Person [ grandparent -> ?Grandparent1 ] \and
  ?ThirdCousin [ grandparent -> ?Grandparent2 ] \and
  fmt_write('checking whether %S is %S\s first cousin\n',
   f2(?Grandparent2,?Grandparent1))@\io,
  ?Grandparent1 [ firstCousin -> ?Grandparent2].

The f2 function is an arbitrary function symbol needed to contain the arguments to fmt_write. Note that Flora produces a warning if you use e.g. f everywhere, with different numbers of arguments. Therefore, we tend to use f followed by the number of arguments, such as f2 for a two-argument container in this case. See the chapter “Flora-2 System Modules” in the Flora-2 manual [1] for more details.

Finally, the \prolog module allows you to call XSB predicates from Flora. This opens up the use of XSB’s (more extensive) built-in library. See the section “Calling Prolog from Flora-2” in the Flora-2 manual [1], and the XSB manual [2] for the list of XSB’s built-in predicates. However, we recommend using Flora predicates whenever possible. For most users, there should be no need to call XSB predicates.

[1](1, 2, 3) Kifer, Michael, Guizhen Yang, Wan Hui, and Chang Zhao. 2014. Flora-2: User’s Manual. 1.0. Stony Brook University, Stony Brook: Department of Computer Science.
[2]Sagonas, K, Terrance Swift, David S Warren, Juliana Freire, Prasad Rao, Hassan Davulcu, and Steve Dawson. 1998. The XSB Programmer’s Manual (Version 1.8). Stony Brook, NY: Department of Computer Science, SUNY at Stony Brook.