Merge pull request #398 from triska/master

Several smaller improvements
This commit is contained in:
Mark Thom
2020-04-25 17:20:24 -03:00
committed by GitHub
2 changed files with 40 additions and 27 deletions

View File

@@ -308,6 +308,12 @@ The modules that ship with Scryer Prolog are also called
`time/1` reports the CPU time of a goal. It is useful
for measuring the performance of your code.
To read contents of external files, use `phrase_from_file/2` from
[`library(pio)`](src/prolog/lib/pio.pl) to apply a DCG to
file contents. The predicates in
[`library(charsio)`](src/prolog/lib/charsio.pl) are also useful for
parsing.
To use predicates provided by the `lists` library, write:
```
@@ -343,7 +349,6 @@ REPL:
```
?- [user].
(type Enter + Ctrl-D to terminate the stream when finished)
:- module(test, [local_member/2]).
:- use_module(library(lists)).

View File

@@ -47,7 +47,7 @@ extend_var_list(Value, VarList, NewVarList, VarType) :-
term_variables(Value, Vars),
extend_var_list_(Vars, 0, VarList, NewVarList, VarType).
extend_var_list_([], N, VarList, VarList, _).
extend_var_list_([], _, VarList, VarList, _).
extend_var_list_([V|Vs], N, VarList, NewVarList, VarType) :-
( var_list_contains_variable(VarList, V) ->
extend_var_list_(Vs, N, VarList, NewVarList, VarType)
@@ -60,36 +60,44 @@ extend_var_list_([V|Vs], N, VarList, NewVarList, VarType) :-
char_type(Char, Type) :-
( var(Char) -> throw(error(instantiation_error, char_type/2))
; atom_length(Char, 1) ->
( ground(Type) -> '$char_type'(Char, Type)
; Type = symbolic_control, '$char_type'(Char, Type)
; Type = layout, '$char_type'(Char, Type)
; Type = symbolic_hexadecimal, Char = x
; Type = octal_digit, '$char_type'(Char, Type)
; Type = binary_digit, '$char_type'(Char, Type)
; Type = hexadecimal_digit, '$char_type'(Char, Type)
; Type = exponent, '$char_type'(Char, Type)
; Type = sign, '$char_type'(Char, Type)
; Type = upper, '$char_type'(Char, Type)
; Type = lower, '$char_type'(Char, Type)
; Type = graphic, '$char_type'(Char, Type)
; Type = alpha, '$char_type'(Char, Type)
; Type = decimal_digit, '$char_type'(Char, Type)
; Type = alnum, '$char_type'(Char, Type)
; Type = meta, '$char_type'(Char, Type)
; Type = solo, '$char_type'(Char, Type)
; Type = prolog, '$char_type'(Char, Type)
; Type = alphabetic, '$char_type'(Char, Type)
; Type = whitespace, '$char_type'(Char, Type)
; Type = control, '$char_type'(Char, Type)
; Type = numeric, '$char_type'(Char, Type)
; Type = ascii, '$char_type'(Char, Type)
; Type = ascii_punctuation, '$char_type'(Char, Type)
; Type = ascii_graphic, '$char_type'(Char, Type)
( ground(Type) ->
( ctype(Type) ->
'$char_type'(Char, Type)
; throw(error(domain_error(char_type, Type), char_type/2))
)
; ctype(Type),
'$char_type'(Char, Type)
)
; throw(error(type_error(in_character, Char), char_type/2))
).
ctype(alnum).
ctype(alpha).
ctype(alphabetic).
ctype(ascii).
ctype(ascii_graphic).
ctype(ascii_punctuation).
ctype(binary_digit).
ctype(control).
ctype(decimal_digit).
ctype(exponent).
ctype(graphic).
ctype(hexadecimal_digit).
ctype(layout).
ctype(lower).
ctype(meta).
ctype(numeric).
ctype(octal_digit).
ctype(prolog).
ctype(sign).
ctype(solo).
ctype(symbolic_control).
ctype(symbolic_hexadecimal).
ctype(upper).
ctype(whitespace).
get_single_char(C) :-
( var(C) -> '$get_single_char'(C)
; atom_length(C, 1) -> '$get_single_char'(C)