Hi,

In wish to achieve contract composition in Fractalide.

I want to create a list of commands where a command has a imported contract 
called a tuple:
Once I can get the Command contracts which includes the Tuple contract I 
can work on a List of Commands.

//tuple.nix
{stdenv, buildFractalideContract, upkeepers
  , ...}:

buildFractalideContract rec {
  src = ./.;
  contract = ''
   @0xf6e41344bb789d96;

    struct Tuple {
      first @0 : Text;
      second @1 : Text;
    }
  '';
}

this is the command contract:

//command.nix
{stdenv, buildFractalideContract, upkeepers
  , tuple
  , ...}:

buildFractalideContract rec {
  src = ./.;
  contract = ''
  @0xdfa17455eb3bee21;

  using Tuple = import "${tuple}/src/contract.capnp";

    struct Command {
      name @0 : Text;
      singles @1 : List(Text);
      kvs @2 : List(Tuple.Tuple);
    }
  '';
}

nix will write the above capnp contracts using this expression:

{ stdenv, writeTextFile, lib, capnproto, capnpc-rust, genName }:
{ src, contract, ... } @ args:

let
name = genName src;
contractText = writeTextFile {
  name = name;
  text = contract;
  executable = false;
};

in stdenv.mkCachedDerivation  (args // {
  name = name;
  unpackPhase = "true";
  installPhase = ''
    runHook preInstall
    mkdir -p $out/src
    cp ${contractText} $out/src/contract.capnp
    ${capnproto}/bin/capnp compile 
-o${capnpc-rust}/bin/capnpc-rust:$out/src/  $out/src/contract.capnp
  '';
})

Now I need to know why I cannot just do this:   using Tuple = import 
"${tuple}/src/contract.capnp";
which will evaluate to using Tuple = import 
"/nix/store/xsibhsqk8n9m7cr0dvy050lq054p0pnd-tuple/src/contract.capnp";

Do I have to use the -I argument to pass into the capnp command? 

Is there a good reason for not allowing absolute paths when importing in 
the contract?

As mentioned here:

"The above imports specify relative paths. If the path begins with a /, it 
is absolute – in this case, the capnp tool searches for the file in each of 
the search path directories specified with -I." 
~ https://capnproto.org/language.html

Composition of contracts should be simple to achieve.

What is the exact syntax in the contract and capnp tool for importing 
absolute path contracts?

Kind regards
Stewart



-- 
You received this message because you are subscribed to the Google Groups 
"Cap'n Proto" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
Visit this group at https://groups.google.com/group/capnproto.

Reply via email to