2

GNU DC displays the stack vertically, (f displays the stack)

1 2 3 4
f  # to display the stack
4
3
2
1

Is there a way to change this to be more like FORTH? While GNU FORTH displays the stack horizontally, (.s displays the stack)

1 2 3 4  ok
.s <4> 1 2 3 4  ok
vonbrand
  • 11,412
  • 8
  • 32
  • 52
Evan Carroll
  • 78,363
  • 46
  • 261
  • 468

1 Answers1

2

You can create custom function in ~/.dcrc which is read each time dc start.

cat ~/.dcrc

[
# if the stack is empty
[ 2 + [stack empty] p 0 :- Q ]s-
z d 0 =- 0 :-
# keep the stack in indexed array -
[ z :- z 0 <- ]s-
l-x
# restore the stack
[ 0 ;- 1 + d ;- ;- r d ;- 1 + r :- 0 ;- d 1 + ;- r !<- ]s-
1 0 ;- 1 + :-
l-x
# displays the stack horizontally
[ 0 ;- d 1 + d ;- ;- n [ ] n d d ;- 1 + r :- ;- !>- ]s-
1 0 ;- 1 + :- l-x [ ok] p 0 :-
]s-

You call it this way :

echo '7 16 8 9' | dc -f - -e 'l-x f'

and you get :

7 16 8 9  ok
9
8
16
7

You cannot use register -

ctac_
  • 2,413
  • 2
  • 7
  • 17