Skip to content

Commit

Permalink
Support ? and ?? operations.
Browse files Browse the repository at this point in the history
  • Loading branch information
corywalker committed May 28, 2018
1 parent 2749274 commit b75227c
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 5 deletions.
14 changes: 13 additions & 1 deletion expreduce/builtin_system.go
Expand Up @@ -330,6 +330,9 @@ func GetSystemDefinitions() (defs []Definition) {
if !ok {
return false, ""
}
if params.es == nil {
return true, "Definiton[<WITHOUT_CONTEXT>]"
}
def, isd := params.es.defined[sym.Name]
if !isd {
return true, "Null"
Expand Down Expand Up @@ -519,8 +522,16 @@ func GetSystemDefinitions() (defs []Definition) {
return this
}

context, contextPath := ActualStringFormArgs(es)
stringParams := ToStringParams{
form: "OutputForm",
context: context,
contextPath: contextPath,
previousHead: "<TOPLEVEL>",
es: es,
}
for i := 1; i < len(this.Parts); i++ {
fmt.Printf("%s", this.Parts[i].String())
fmt.Printf("%s", this.Parts[i].StringForm(stringParams))
}
fmt.Printf("\n")
return NewSymbol("System`Null")
Expand Down Expand Up @@ -784,5 +795,6 @@ func GetSystemDefinitions() (defs []Definition) {
Name: "Defer",
OmitDocumentation: true,
})
defs = append(defs, Definition{Name: "Information"})
return
}
2 changes: 1 addition & 1 deletion expreduce/definition.go
Expand Up @@ -68,5 +68,5 @@ func (def *Def) StringForm(defSym *Symbol, params ToStringParams) string {
)
buffer = append(buffer, e.StringForm(params))
}
return strings.Join(buffer[:], "\n")
return strings.Join(buffer[:], "\n\n")
}
1 change: 1 addition & 0 deletions expreduce/evalstate.go
Expand Up @@ -134,6 +134,7 @@ func (es *EvalState) Init(loadAllDefs bool) {
es.MarkSeen("System`Complex")
es.MarkSeen("System`Integers")
es.MarkSeen("System`Break")
es.MarkSeen("System`LongForm")

es.MarkSeen("System`Exp")
es.MarkSeen("System`AppellF1")
Expand Down
13 changes: 12 additions & 1 deletion expreduce/interp.go
Expand Up @@ -337,7 +337,7 @@ func ParserExprConv(expr *wl.Expression) Ex {
e,
ParserExprConv(expr.Expression2),
})
case 140:
case wl.ExpressionMessageName:
return NewExpression([]Ex{
NewSymbol("System`MessageName"),
ParserTokenConv(expr.Token),
Expand Down Expand Up @@ -452,6 +452,17 @@ func ParserExprConv(expr *wl.Expression) Ex {
NewSymbol("System`Sqrt"),
ParserExprConv(expr.Expression),
})
case wl.ExpressionInfo:
return E(
S("Information"),
ParserTagConv(expr.Tag),
)
case wl.ExpressionInfoShort:
return E(
S("Information"),
ParserTagConv(expr.Tag),
E(S("Rule"), S("LongForm"), S("False")),
)
}
log.Fatalf("System`UnParsed: %+v %+v %+v", expr.Token, expr.Case, expr)
return nil
Expand Down
4 changes: 2 additions & 2 deletions expreduce/resources.go

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions expreduce/resources/system.m
Expand Up @@ -325,3 +325,14 @@

Definition::usage = "`Definition[sym]` renders the attributes, downvalues, and default value of `sym`.";
Attributes[Definition] = {HoldAll, Protected};

Information::usage = "`Information[sym]` renders the usage, attributes, downvalues, and default value of `sym`.";
Information[sym_Symbol, LongForm->useLongForm_] := (
Print[sym::usage];
If[useLongForm,
Print[""];
Print[Definition[sym]];
];
);
Information[sym_Symbol] := Information[sym, LongForm->True];
Attributes[Information] = {HoldAll, Protected, ReadProtected};

0 comments on commit b75227c

Please sign in to comment.