Advertisement
Guest User

Untitled

a guest
Jan 16th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. #/._?NumberQ->0/.x_String:>StringReplace[x,_->" "]&
  2. StringReplace[#,_->" "]~Check~#&//@#/._?NumberQ->0&
  3.  
  4. #/._?NumberQ->0
  5.  
  6. .../.x_String:>StringReplace[x,_->" "]
  7.  
  8. StringReplace[#,_->" "]~Check~#&//@...
  9.  
  10. InstallOtherMethod(Zero,[IsChar],c->' ');
  11. InstallOtherMethod(Zero,[IsList],l->List(l,Zero));
  12.  
  13. gap> Zero([[["H"],"e",1,1,0],[[-3],"arth"]]);
  14. [ [ [ " " ], " ", 0, 0, 0 ], [ [ 0 ], " " ] ]
  15.  
  16. f:=function(x)if IsInt(x)then return 0;elif IsList(x)then return List(x,f);fi;return' ';end;
  17.  
  18. f=->a{a.map{|x|x*0==0?0:x*0==""?x.gsub(/./," "):f[x]}}
  19.  
  20. class N a where n::a->a
  21. instance N Int where n _=0
  22. instance N Char where n _=' '
  23. instance N a=>N[a]where n=map n
  24.  
  25. *Main> n (42::Int)
  26. 0
  27. *Main> n "hi"
  28. " "
  29. *Main> n ([[1,2],[3,4,5]]::[[Int]])
  30. [[0,0],[0,0,0]]
  31. *Main> n ["hello","world!"]
  32. [" "," "]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement