Advertisement
EBobkunov

prompt claude

Feb 6th, 2025
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 5.28 KB | None | 0 0
  1. Finally, implement for #lists: `TypeList`, `List`, `ConsList`, `Head`, `Tail`, `IsEmpty`
  2. **Lists**
  3.  
  4. ```stella
  5. extend with #lists;
  6. Copy
  7. ```
  8.  
  9. A list is a homogenous collection of elements of an arbitrary length. Its type is written as `[Type]`, and it is constructed using either the `cons` expression which accepts the head and the tail to be linked, or using the `[expr1, expr2, ...]` syntax. The first element of the list can be accessed using `List::head`, the remaining elements (as a list) using `List::tail`, and you can check if it's empty using `List::isempty`.
  10.  
  11. ```stella
  12. language core;
  13.  
  14. extend with #lists;
  15. extend with #multiparameter-functions;
  16.  
  17. fn nonempty(list : [Nat]) -> Bool {
  18.  return if List::isempty(list) then true else false
  19. }
  20.  
  21. fn first_or_default(list : [Nat], default : Nat) -> Nat {
  22.  return if nonempty(list) then List::head(list) else default
  23. }
  24.  
  25. fn main(default : Nat) -> Nat {
  26.  return first_or_default([], default)
  27. }
  28. ```
  29.  
  30.  
  31. ```
  32. // File generated by the BNF Converter (bnfc 2.9.5).
  33.  
  34. package org.syntax.stella.Absyn;
  35.  
  36. public class TypeList  extends Type {
  37.  public final Type type_;
  38.  public int line_num, col_num, offset;
  39.  public TypeList(Type p1) { type_ = p1; }
  40.  
  41.  public  R accept(org.syntax.stella.Absyn.Type.Visitor v, A arg) { return v.visit(this, arg); }
  42.  
  43.  public boolean equals(java.lang.Object o) {
  44.    if (this == o) return true;
  45.    if (o instanceof org.syntax.stella.Absyn.TypeList) {
  46.      org.syntax.stella.Absyn.TypeList x = (org.syntax.stella.Absyn.TypeList)o;
  47.      return this.type_.equals(x.type_);
  48.    }
  49.    return false;
  50.  }
  51.  
  52.  public int hashCode() {
  53.    return this.type_.hashCode();
  54.  }
  55.  
  56.  
  57. }
  58. ```
  59.  
  60.  
  61.  
  62. ```
  63. // File generated by the BNF Converter (bnfc 2.9.5).
  64.  
  65. package org.syntax.stella.Absyn;
  66.  
  67. public class List  extends Expr {
  68.  public final ListExpr listexpr_;
  69.  public int line_num, col_num, offset;
  70.  public List(ListExpr p1) { listexpr_ = p1; }
  71.  
  72.  public  R accept(org.syntax.stella.Absyn.Expr.Visitor v, A arg) { return v.visit(this, arg); }
  73.  
  74.  public boolean equals(java.lang.Object o) {
  75.    if (this == o) return true;
  76.    if (o instanceof org.syntax.stella.Absyn.List) {
  77.      org.syntax.stella.Absyn.List x = (org.syntax.stella.Absyn.List)o;
  78.      return this.listexpr_.equals(x.listexpr_);
  79.    }
  80.    return false;
  81.  }
  82.  
  83.  public int hashCode() {
  84.    return this.listexpr_.hashCode();
  85.  }
  86.  
  87.  
  88. }
  89. ```
  90.  
  91.  
  92.  
  93. ```
  94. // File generated by the BNF Converter (bnfc 2.9.5).
  95.  
  96. package org.syntax.stella.Absyn;
  97.  
  98. public class ConsList  extends Expr {
  99.  public final Expr expr_1, expr_2;
  100.  public int line_num, col_num, offset;
  101.  public ConsList(Expr p1, Expr p2) { expr_1 = p1; expr_2 = p2; }
  102.  
  103.  public  R accept(org.syntax.stella.Absyn.Expr.Visitor v, A arg) { return v.visit(this, arg); }
  104.  
  105.  public boolean equals(java.lang.Object o) {
  106.    if (this == o) return true;
  107.    if (o instanceof org.syntax.stella.Absyn.ConsList) {
  108.      org.syntax.stella.Absyn.ConsList x = (org.syntax.stella.Absyn.ConsList)o;
  109.      return this.expr_1.equals(x.expr_1) && this.expr_2.equals(x.expr_2);
  110.    }
  111.    return false;
  112.  }
  113.  
  114.  public int hashCode() {
  115.    return 37*(this.expr_1.hashCode())+this.expr_2.hashCode();
  116.  }
  117.  
  118.  
  119. }
  120. ```
  121.  
  122.  
  123.  
  124. ```
  125. // File generated by the BNF Converter (bnfc 2.9.5).
  126.  
  127. package org.syntax.stella.Absyn;
  128.  
  129. public class Head  extends Expr {
  130.  public final Expr expr_;
  131.  public int line_num, col_num, offset;
  132.  public Head(Expr p1) { expr_ = p1; }
  133.  
  134.  public  R accept(org.syntax.stella.Absyn.Expr.Visitor v, A arg) { return v.visit(this, arg); }
  135.  
  136.  public boolean equals(java.lang.Object o) {
  137.    if (this == o) return true;
  138.    if (o instanceof org.syntax.stella.Absyn.Head) {
  139.      org.syntax.stella.Absyn.Head x = (org.syntax.stella.Absyn.Head)o;
  140.      return this.expr_.equals(x.expr_);
  141.    }
  142.    return false;
  143.  }
  144.  
  145.  public int hashCode() {
  146.    return this.expr_.hashCode();
  147.  }
  148.  
  149.  
  150. }
  151. ```
  152.  
  153.  
  154.  
  155. ```
  156. // File generated by the BNF Converter (bnfc 2.9.5).
  157.  
  158. package org.syntax.stella.Absyn;
  159.  
  160. public class Tail  extends Expr {
  161.  public final Expr expr_;
  162.  public int line_num, col_num, offset;
  163.  public Tail(Expr p1) { expr_ = p1; }
  164.  
  165.  public  R accept(org.syntax.stella.Absyn.Expr.Visitor v, A arg) { return v.visit(this, arg); }
  166.  
  167.  public boolean equals(java.lang.Object o) {
  168.    if (this == o) return true;
  169.    if (o instanceof org.syntax.stella.Absyn.Tail) {
  170.      org.syntax.stella.Absyn.Tail x = (org.syntax.stella.Absyn.Tail)o;
  171.      return this.expr_.equals(x.expr_);
  172.    }
  173.    return false;
  174.  }
  175.  
  176.  public int hashCode() {
  177.    return this.expr_.hashCode();
  178.  }
  179.  
  180.  
  181. }
  182. ```
  183.  
  184.  
  185.  
  186. ```
  187. // File generated by the BNF Converter (bnfc 2.9.5).
  188.  
  189. package org.syntax.stella.Absyn;
  190.  
  191. public class IsEmpty  extends Expr {
  192.  public final Expr expr_;
  193.  public int line_num, col_num, offset;
  194.  public IsEmpty(Expr p1) { expr_ = p1; }
  195.  
  196.  public  R accept(org.syntax.stella.Absyn.Expr.Visitor v, A arg) { return v.visit(this, arg); }
  197.  
  198.  public boolean equals(java.lang.Object o) {
  199.    if (this == o) return true;
  200.    if (o instanceof org.syntax.stella.Absyn.IsEmpty) {
  201.      org.syntax.stella.Absyn.IsEmpty x = (org.syntax.stella.Absyn.IsEmpty)o;
  202.      return this.expr_.equals(x.expr_);
  203.    }
  204.    return false;
  205.  }
  206.  
  207.  public int hashCode() {
  208.    return this.expr_.hashCode();
  209.  }
  210.  
  211.  
  212. }
  213. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement