about summary refs log tree commit diff stats
path: root/same-fringe.mu
blob: b9235006e72bfc1edab1b6a5824f279f088a32e0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# The 'same fringe' problem: http://wiki.c2.com/?SameFringeProblem
# Example program demonstrating coroutines using Mu's delimited continuations.
#
# Expected output:
#   1
# (i.e. that the two given trees x and y have the same leaves, in the same
# order from left to right)

container tree:_elem [
  val:_elem
  left:&:tree:_elem
  right:&:tree:_elem
]

def main [
  local-scope
  # x: ((a b) c)
  # y: (a (b c))
  a:&:tree:num <- new-tree 3
  b:&:tree:num <- new-tree 4
  c:&:tree:num <- new-tree 5
  x1:&:tree:num <- new-tree a, b
  x:&:tree:num <- new-tree x1, c
  y1:&:tree:num <- new-tree b, c
  y:&:tree:num <- new-tree a, y1
  result:bool <- same-fringe x, y
  $print result 10/newline
]

def same-fringe a:&:tree:_elem, b:&:tree:_elem -> result:bool [
  local-scope
  load-inputs
  k1:continuation <- call-with-continuation-mark 100/mark, process, a
  k2:continuation <- call-with-continuation-mark 100/mark, process, b
  {
    k1, x:_elem, a-done?:bool <- call k1
    k2, y:_elem, b-done?:bool <- call k2
    break-if a-done?
    break-if b-done?
    match?:bool <- equal x, y
    return-unless match?, false
    loop
  }
  result <- and a-done?, b-done?
]

# harness around traversal
def process t:&:tree:_elem [
  local-scope
  load-inputs
  return-continuation-until-mark 100/mark  # initial
  traverse t
  zero-val:&:_elem <- new _elem:type
  return-continuation-until-mark 100/mark, *zero-val, true/done  # final
  assert false, [continuation called past done]
]

# core traversal
def traverse t:&:tree:_elem [
  local-scope
  load-inputs
  return-unless t
  l:&:tree:_elem <- get *t, left:offset
  traverse l
  r:&:tree:_elem <- get *t, right:offset
  traverse r
  return-if l
  return-if r
  # leaf
  v:_elem <- get *t, val:offset
  return-continuation-until-mark 100/mark, v, false/not-done
]

# details

def new-tree x:_elem -> result:&:tree:_elem [
  local-scope
  load-inputs
  result <- new {(tree _elem): type}
  put *result, val:offset, x
]

def new-tree l:&:tree:_elem, r:&:tree:_elem -> result:&:tree:_elem [
  local-scope
  load-inputs
  result <- new {(tree _elem): type}
  put *result, left:offset, l
  put *result, right:offset, r
]
 


     
 
                                                         
                                                             
                                                       
                        
 





                                                                         
 

        
 
                                       

                                                       
                              
                                                                       
                                                         
                                

 










                                                 

               
 


                                                                      
 
                                                                  
 




                                                                          
 

                                                                       
 
 

                             
 


                                                                       
 
                                
 

                                                                          
 

                                                     
 
 

               
 
                                                                  
 

                                                                          
 

                                                                         
Ranger v.1.1.1
==============

Ranger is a free console file manager that gives you greater flexibility
and a good overview of your files without having to leave your *nix console.
It visualizes the directory tree in two dimensions: the directory hierarchy
on one, lists of files on the other, with a preview to the right so you know
where you'll be going.  The default keys are similar to those of Vim, Emacs
and Midnight Commander, though Ranger is easily controllable with just the
arrow keys or the mouse.

The program is written in Python (2.6 or 3.1) and uses curses for the
text-based user interface.


About
-----

* Author:          Roman Zimbelmann  <romanz@lavabit.com>
* Website:         http://savannah.nongnu.org/projects/ranger
* License:         GNU General Public License Version 3
* Version:         1.1.1

* Download URL of the newest stable version:
http://git.savannah.gnu.org/cgit/ranger.git/snapshot/ranger-stable.tar.gz

* Git Clone URL:
git clone http://git.sv.gnu.org/r/ranger.git


Features
--------

* Multi-column display (Miller Columns)
* Preview of the selected file/directory
* Common file operations (create/chmod/copy/delete/...)
* VIM-like console and hotkeys
* Automatically determine file types and run them with correct programs
* Change the directory of your shell after exiting ranger
* Tabs, Bookmarks, Mouse support


Dependencies
------------

* A *nix-like operating system
* Python 2.6 or Python 3.1 with the curses module

Optional:
* The "file" program
* A pager ("less" by default)


Getting Started
---------------

Ranger can be started without installing.  Just run the executable (in
a terminal.)  The switch "--clean" will prevent it from creating or
accessing configuration files.

Follow the instructions in the INSTALL file for installing ranger.

After starting ranger, you should see 4 columns. The third one is the main
column, the directory where you're currently at.  To the left you see the
parent directories and to the right there's a preview of the object you're
pointing at.  Now use the Arrow Keys to navigate, Enter to open a file
or type Q to quit.

To customize ranger, copy the files from ranger/defaults/ to ~/.ranger/
and modify them according to your wishes.


Troubleshooting, Getting Help
-----------------------------

If you encounter an error, try running ranger with --debug.  This will
sometimes display more detailed information about the error.  Also, try
deactivating optimization:

PYTHONOPTIMIZE="" ranger --debug

Report bugs on savannah:  (please include as much information as possible)
http://savannah.nongnu.org/bugs/?func=additem&group=ranger

Ask questions on the mailing list:
http://lists.nongnu.org/mailman/listinfo/ranger-users


Further Reading
---------------

Check the man page for information on common features and hotkeys.

The most detailed manual is accessible by pressing "?" from inside ranger.
It is also available at ranger/help/, contained in the *.py files.

The file ranger/defaults/keys.py contains all key combinations, so that's
another place you may want to check out.