Paste: stack declaration problem

Author: JimMack1963
Mode: factor
Date: Sun, 25 Apr 2010 19:11:33
Plain Text |
USING: editors fry io io.encodings.utf8 io.files io.files.temp
io.files.unique.private io.launcher io.pathnames kernel nested-comments
prettyprint sequences strings ;
IN: learn

(* I've got 
    "complicated stuff" [ dup print ] with-editor 
    working, but was hoping to be able to genericize "ed" as a debug tool to cut down on typing
    and I ran into stack declaration problems I don't seem to experiment my way out of.
      *)

: with-capture ( quot ext -- fname ) 
    [ random-name ] dip append temp-file 
    [ [ utf8  ] curry  dip 
    '[ _ call( -- ) ] with-file-writer ] keep  ; inline  
   
: with-editor ( quot -- ) ".txt" with-capture 0 edit-location ;    
: with-browser ( quot -- ) ".html" with-capture 
    [ <pathname> . ] 
    [ [ { "cmd.exe" } ] dip "/c \"" "\"" surround suffix run-detached drop ] bi ; 
   
! intended usage: (works)    
! "complicated stuff" [ dup print ] with-editor     

! Problems arise with callstack:
GENERIC: ed (   --  ) 
M: string ed (  --  ) [  print ]  with-editor  ;

(*  can't parse:
Stack effect declaration is wrong
inferred (( x -- x ))
declared (( -- ))
*)

! Problems arise with callstack:
GENERIC: ed2 (   --  ) 
M: string ed2 (  --  ) [ dup print ]  with-editor  ;

(*  can't parse:
Stack effect declaration is wrong
inferred (( x -- x ))
declared (( -- ))
*)

GENERIC: ed3 ( x  -- x ) 
M: string ed3 ( x -- x ) [ print ]  with-editor  ;

(*  can't run:
Quotation's stack effect does not match call site
quot      [ print ]
call-site (( -- ))
*)

New Annotation

Summary:
Author:
Mode:
Body: