:vars and .vars

db4
Slava Pestov 2008-02-21 01:26:44 -06:00
parent c5de10ec49
commit 6c0dd93ff1
5 changed files with 25 additions and 5 deletions

View File

@ -31,6 +31,9 @@ M: string error. print ;
: :get ( variable -- value )
error-continuation get continuation-name assoc-stack ;
: :vars ( -- )
error-continuation get continuation-name namestack. ;
: :res ( n -- )
1- restarts get-global nth f restarts set-global restart ;

11
core/inspector/inspector.factor Normal file → Executable file
View File

@ -1,4 +1,4 @@
! Copyright (C) 2005, 2007 Slava Pestov.
! Copyright (C) 2005, 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: arrays generic hashtables io kernel assocs math
namespaces prettyprint sequences strings io.styles vectors words
@ -93,6 +93,15 @@ SYMBOL: +editable+
: describe ( obj -- ) H{ } describe* ;
: namestack. ( seq -- )
[
[ global eq? not ] subset
[ keys ] map concat prune
] keep [ dupd assoc-stack ] curry H{ } map>assoc describe ;
: .vars ( -- )
namestack namestack. ;
SYMBOL: inspector-hook
[ H{ { +number-rows+ t } } describe* ] inspector-hook set-global

11
core/mirrors/mirrors.factor Normal file → Executable file
View File

@ -1,8 +1,8 @@
! Copyright (C) 2007 Slava Pestov.
! Copyright (C) 2007, 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: assocs hashtables kernel sequences generic words
arrays classes slots slots.private tuples math vectors
quotations ;
quotations sorting prettyprint ;
IN: mirrors
GENERIC: object-slots ( obj -- seq )
@ -69,8 +69,13 @@ M: enum clear-assoc enum-seq delete-all ;
INSTANCE: enum assoc
: sort-assoc ( assoc -- alist )
>alist
[ dup first unparse-short swap ] { } map>assoc
sort-keys values ;
GENERIC: make-mirror ( obj -- assoc )
M: hashtable make-mirror ;
M: hashtable make-mirror sort-assoc ;
M: integer make-mirror drop f ;
M: array make-mirror <enum> ;
M: vector make-mirror <enum> ;

View File

@ -67,7 +67,7 @@ unit-test
[ "[ \\ [ ]" ] [ [ \ [ ] unparse ] unit-test
[ t ] [
100 \ dup <array> [ pprint-short ] with-string-writer
100 \ dup <array> unparse-short
"{" head?
] unit-test

View File

@ -75,6 +75,9 @@ combinators quotations ;
{ string-limit t }
} clone [ pprint ] bind ;
: unparse-short ( obj -- str )
[ pprint-short ] with-string-writer ;
: short. ( obj -- ) pprint-short nl ;
: .b ( n -- ) >bin print ;