Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

My mother is a fish. -- William Faulkner


devel / comp.lang.prolog / Re: too slow DCG!

SubjectAuthor
* too slow DCG!João Aragão
`- Re: too slow DCG!Alex Grabowski

1
too slow DCG!

<8095aeb1-3383-4fb0-a022-29edbcdb83f0n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1754&group=comp.lang.prolog#1754

  copy link   Newsgroups: comp.lang.prolog
X-Received: by 2002:a05:620a:17a8:b0:6ce:99f0:7626 with SMTP id ay40-20020a05620a17a800b006ce99f07626mr14131259qkb.194.1663615201523;
Mon, 19 Sep 2022 12:20:01 -0700 (PDT)
X-Received: by 2002:a81:bf4b:0:b0:34d:17dc:3cc1 with SMTP id
s11-20020a81bf4b000000b0034d17dc3cc1mr2539445ywk.119.1663615201232; Mon, 19
Sep 2022 12:20:01 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.prolog
Date: Mon, 19 Sep 2022 12:20:01 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=2804:d59:8640:7b00:dc21:cc01:6fed:e55c;
posting-account=4s1b3QoAAADFW5eoT5KQ083USZpTYgMq
NNTP-Posting-Host: 2804:d59:8640:7b00:dc21:cc01:6fed:e55c
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <8095aeb1-3383-4fb0-a022-29edbcdb83f0n@googlegroups.com>
Subject: too slow DCG!
From: joao.sales.aragao@gmail.com (João Aragão)
Injection-Date: Mon, 19 Sep 2022 19:20:01 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1640
 by: João Aragão - Mon, 19 Sep 2022 19:20 UTC

Hey. I'm trying to make a program with DCG that recognizes a list of variables as such:
x1, x9, a, b, ..., z

it's getting like this:

var -->
[X], var, {char_type(X, alnum)}
| [X], var, {X='_'}.

var -->
[X], {char_type(X, alnum)}
| [X], {X='_'}.

var-list -->
var, [,], var-list, !.

var-list -->
var.

the problem is that when i try to run phrase(var-list, X), if X is a fairly lengthily list like [a,,,b,,,c,,,d,,,e,,,f,,,g,,,h,,,i,,,j,,,k, ')'] it backtracks too much before returning "false"! ( ')' is not part of list of variables)

any suggestions???

Re: too slow DCG!

<tgf2hs$1qnj8$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1761&group=comp.lang.prolog#1761

  copy link   Newsgroups: comp.lang.prolog
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: hurufu@gmail.com (Alex Grabowski)
Newsgroups: comp.lang.prolog
Subject: Re: too slow DCG!
Date: Wed, 21 Sep 2022 13:11:24 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 54
Message-ID: <tgf2hs$1qnj8$1@dont-email.me>
References: <8095aeb1-3383-4fb0-a022-29edbcdb83f0n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 21 Sep 2022 13:11:24 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="393a9d7a0197ff7cb54c71329ba2d6ba";
logging-data="1924712"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+iauQHcSG9y/fqcYmpFjAe"
User-Agent: Pan/0.151 (Butcha; a6f6327)
Cancel-Lock: sha1:4+0v7ZlBzd6XtdibA5kImgYRgWY=
 by: Alex Grabowski - Wed, 21 Sep 2022 13:11 UTC

User João Aragão wrote:

> Hey. I'm trying to make a program with DCG that recognizes a list of
> variables as such:
> x1, x9, a, b, ..., z
>
> it's getting like this:
>
> var -->
> [X], var, {char_type(X, alnum)}
> | [X], var, {X='_'}.
>
> var -->
> [X], {char_type(X, alnum)}
> | [X], {X='_'}.
>
>
> var-list -->
> var, [,], var-list, !.
>
> var-list -->
> var.
>
> the problem is that when i try to run phrase(var-list, X), if X is a
> fairly lengthily list like [a,,,b,,,c,,,d,,,e,,,f,,,g,,,h,,,i,,,j,,,k,
> ')'] it backtracks too much before returning "false"! ( ')' is not part
> of list of variables)
>
> any suggestions???

Hi,

I think the main issue is that var-list has the base case at the last
position and not the first, that's why it loops, also var//2 isn't too
clear for me, it has unnecessary recursive definition.

If you insist on using char_type/2 then I would've written something like
this (tested in SWI):

:- set_prolog_flag(double_quotes, chars).
variable_list --> variable.
variable_list --> variable, variable_list_aux.
variable_list_aux --> ",", variable_list.
variable --> ("_" | alpha), alnums.
alnums --> [] | ("_" | alnum), alnums.
alnum --> [X], { char_type(X, alnum) }.
alpha --> [X], { char_type(X, alpha) }.

Please try to avoid cut operator in simple DCGs like yours and also try
not to use var-list, but use var_list instead, because the first one will
be parsed as -(var, list).

--
Best wishes

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor