Did you know ... Search Documentation:
Pack logtalk -- logtalk-3.86.0/examples/classmethods/SCRIPT.txt

This file is part of Logtalk https://logtalk.org/ SPDX-FileCopyrightText: 1998-2023 Paulo Moura <pmoura@logtalk.org> SPDX-License-Identifier: Apache-2.0

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

% start by loading the example:

| ?- logtalk_load(classmethods(loader)). ...

% use the "class method" area/2 to calculate the are of a circle given its radius:

| ?- circle::area(1.0, Area). Area = 3.14159 yes

% ask our static instance, c42, its area:

| ?- c42::area(Area). Area = 24.6301 yes

% create a dynamic instance of class circle using the "class method" new/4:

| ?- circle::new(1.2, 7.9, 2.0, Circle). Circle = o1 yes

% ask the circle o1 its area:

| ?- o1::area(Area). Area = 4.52389 yes