1 /* 2 * #%L 3 * prolobjectlink-jpi 4 * %% 5 * Copyright (C) 2019 Prolobjectlink Project 6 * %% 7 * Permission is hereby granted, free of charge, to any person obtaining a copy 8 * of this software and associated documentation files (the "Software"), to deal 9 * in the Software without restriction, including without limitation the rights 10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 * copies of the Software, and to permit persons to whom the Software is 12 * furnished to do so, subject to the following conditions: 13 * 14 * The above copyright notice and this permission notice shall be included in 15 * all copies or substantial portions of the Software. 16 * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 * THE SOFTWARE. 24 * #L% 25 */ 26 package io.github.prolobjectlink.prolog; 27 28 /** 29 * Prolog term that represent variable data type. Prolog variables are created 30 * using {@link PrologProvider#newVariable(int)} for anonymous variables and 31 * {@link PrologProvider#newVariable(String, int)} for named variables. The 32 * Prolog variables can be used and reused because they remain in java heap. You 33 * can instantiate a prolog variable and used it any times in the same clause 34 * because refer to same variable every time. 35 * 36 * <pre> 37 * 38 * PrologVariable x = provider.newVariable("X"); 39 * PrologVariable y = provider.newVariable("Y"); 40 * PrologVariable z = provider.newVariable("Z"); 41 * engine.assertz(provider.newStructure(grandparent, x, z), provider.newStructure(parent, x, y), 42 * provider.newStructure(parent, y, z)); 43 * 44 * </pre> 45 * 46 * 47 * @author Jose Zalacain 48 * @since 1.0 49 */ 50 public interface PrologVariable extends PrologTerm { 51 52 /** 53 * Check that current variable be an anonymous variable 54 * 55 * @return - true if the current variable is an anonymous variable, false in 56 * other case 57 * @since 1.0 58 */ 59 public boolean isAnonymous(); 60 61 /** 62 * Name that identify this variable 63 * 64 * @return variable name 65 * @since 1.0 66 */ 67 public String getName(); 68 69 /** 70 * Set the name for current prolog variable term. If the under-laying prolog 71 * variable term don't have rename option, a new under-laying variable is 72 * created with the given name. 73 * 74 * @param name name to be set to the current variable. 75 * @since 1.0 76 */ 77 public void setName(String name); 78 79 /** 80 * Non negative integer that represent the variable position of the Structure 81 * where the variable is first time declared. 82 * 83 * @return the variable position 84 * @since 1.0 85 */ 86 public int getPosition(); 87 88 }