]> gitweb.factorcode.org Git - factor.git/blob - basis/present/present.factor
975973e84dfa683865e8cff31845d9260e14aa9e
[factor.git] / basis / present / present.factor
1 ! Copyright (C) 2008, 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors alien.c-types effects io.pathnames kernel math
4 math.parser quotations sequences strings vocabs words ;
5 IN: present
6
7 GENERIC: present ( object -- string )
8
9 M: real present number>string ;
10
11 M: complex present ( c -- str )
12     [ real>> number>string ]
13     [
14         imaginary>>
15         [ number>string ]
16         [ 0 >= [ "+" prepend ] when ] bi
17     ] bi "j" 3append ;
18
19 M: string present ;
20
21 M: word present name>> ;
22
23 M: vocab-spec present name>> ;
24
25 M: effect present effect>string ;
26
27 M: f present drop "" ;
28
29 M: pathname present string>> ;
30
31 M: callable present
32     [ "[ ]" ] [
33         [ drop "[ " ]
34         [ [ present ] map " " join ]
35         [ drop " ]" ] tri 3append
36     ] if-empty ;
37
38 M: pointer present
39     to>> name>> "*" append ;