List comprehensions in queries.

Bjorn Turesson btu@REDACTED
Thu Feb 25 07:55:57 CET 1999


On Wed, 24 Feb 1999, Bijan Parsia wrote:

> Are there additional restrictions on list comprehensions in queries?
> 
> 
> I have the following query:
> 
>    		PathLength = length(Path) + Depth,
>        	F = fun() ->
>             Q = query [Item || Item <- table(cvn_path_item),
>                             lists:prefix(Path, Item.path),
>                             length(Item.path) =< PathLength]
>                                      end,
>                 mnemosyne:eval(Q)
>             end,
> 
> Where #cvn_path_item.path is a list.
> 
> If I try this I get:
> 
> 	{aborted,{badarg,{ets,lookup,
>                       [db_get,[mnemosyne_catalog,{image,cvn_path_item}]]}}}
> 
> But if I do the query, and then do the rest of the list comprehension on
> the result, it works fine.
> 
> Help?
> 
> Cheers,
> Bijan Parsia.

I don't have the opensource release testable at my hands, but you did
remeber to start mnesia and mnemosyne, didn't you?
The following shell interaction works for me (slightly different release)
using the code shown below.
		
				// Bjoern


--------------------------------------------------
btu@REDACTED:mne$ erl
Erlang (JAM) emulator version 4.7.3.3
 
Eshell V4.7.3.3  (abort with ^G)
1> c(q).
{ok,q}
2> q:s().
{atomic,ok}
3> q:add_path([1,2,3,4,5]), q:add_path([2,3,4,5,6]),
q:add_path([3,4,5,6,7]).
{atomic,ok}
4> q:tstPath([2,3,4], 9999).
{atomic,[{cvn_path_item,[2,3,4,5,6],undefined}]}
--------------------------------------------------
Code as follows:

-module(q).
-export([s/0,add_path/1, tstPath/2]).
-include_lib("mnemosyne/include/mnemosyne.hrl").

-record (cvn_path_item, {path, other_fields}).


s () ->
    mnesia:start (),
    application:start(mnemosyne),
    mnesia:create_table (cvn_path_item, 
                 [{attributes, record_info(fields, cvn_path_item)}]).

add_path (Path) ->
    Fun = fun () ->
                  mnesia:write (#cvn_path_item{path=Path})
          end,
    mnesia:transaction (Fun).


tstPath (Path, Depth) ->
    PathLength = erlang:length(Path) + Depth,
    F = fun() ->
		Q = query [Item || Item <- table(cvn_path_item),
				   lists:prefix(Path, Item.path),  
				   erlang:length(Item.path) =< PathLength]
		    end,
		mnemosyne:eval(Q)
	end,
    mnesia:transaction(F).

--------------------------------------------------------------


--
Mouse moved last hour: 9.23, today: 9.23, this week: 870.62 (meters)




More information about the erlang-questions mailing list