Closed Kranthi-Sai closed 1 year ago
import Debug "mo:base/Debug"; import List "mo:base/List"; import Text "mo:base/Text"; import Nat "mo:base/Nat";
actor UserDatabase { public type UserData = { userId : Text; earnPoints : Nat; }; stable var userd : List.List = List.nil();
public func saveUser(userDataText : Text, earnPointsNat : Nat) { let newUser : UserData = { userId = userDataText; earnPoints = earnPointsNat; };
userd := List.push(newUser, userd); Debug.print(debug_show (userd));
};
public query func read() : async [UserData] { return List.toArray(userd); };
public func deleteUser(userIdToDelete: Text) { let newUserd = List.filter((user) => user.userId != userIdToDelete, userd); userd := newUserd; Debug.print("User deleted with userId: " # userIdToDelete); };
}; error: Error [M0001] in file Main.mo:27:36 unexpected token '=', expected one of token or sequence: ) . ! <exp_nullary(ob)> <exp(ob)> |> <exp_bin(ob)> or <exp_bin(ob)> <exp(ob)> implies <exp_bin(ob)> <exp_bin(ob)> . , seplist(<exp(ob)>,,) : <exp_bin(ob)> <exp(ob)> and <exp_bin(ob)> <exp_bin(ob)> <exp_nullary(ob)> [ <exp(ob)> ]
import Debug "mo:base/Debug"; import List "mo:base/List"; import Text "mo:base/Text"; import Nat "mo:base/Nat";
actor UserDatabase { public type UserData = { userId : Text; earnPoints : Nat; }; stable var userd : List.List = List.nil();
public func saveUser(userDataText : Text, earnPointsNat : Nat) { let newUser : UserData = { userId = userDataText; earnPoints = earnPointsNat; };
};
public query func read() : async [UserData] { return List.toArray(userd); };
public func deleteUser(userIdToDelete: Text) { let newUserd = List.filter((user) => user.userId != userIdToDelete, userd); userd := newUserd; Debug.print("User deleted with userId: " # userIdToDelete); };
}; error: Error [M0001] in file Main.mo:27:36 unexpected token '=', expected one of token or sequence: ) . ! <exp_nullary(ob)> <exp(ob)> |> <exp_bin(ob)> or <exp_bin(ob)> <exp(ob)> implies <exp_bin(ob)> <exp_bin(ob)> . , seplist(<exp(ob)>,,) : <exp_bin(ob)> <exp(ob)> and <exp_bin(ob)> <exp_bin(ob)> <exp_nullary(ob)> [ <exp(ob)> ]