flang the compiler proves your program cannot hang 0.9.0 GitHub Try in the browserTry it Русский

String lists

Lists of strings: first, last, tail, join, access by index, common prefix.

Import:

  использует «String lists»

Example

File example.flang:

модуль «Пример»
  использует «String lists»

тотальная функция «Вызов из примера»
  возвращает строка
  пример «Три слова»
    ожидается "пол"
  «Общее начало» от ["полёт", "полка", "полено"]
$ flang test example.flang
example.flang: примеров 33, прошло 33, не прошло 0

The command runs the tests of the module and the test in the file: 33 in total. The value on the ожидается line comes from the test of «Общее начало» in the module source.

Functions

Functions to call: 12; internal: 1, listed at the end of the page.

Every postcondition has a status: proved — holds for any arguments; checked on tests only — no violation on the values from the tests, other arguments are checked at run time; not proved — there is no proof, the condition is checked at run time.

Used most often in the examples and in other modules: «Строка по номеру», «Первая строка», «Хвост через», «Слова».

«Первая строка»

принимает части: список строки
возвращает строка

Test from the module: given части = ["автор", "Стругацкие"] returns "автор".

«Строка по номеру»

принимает части: список строки, номер: неотрицательное, запасная: строка
возвращает строка

Test from the module: given части = ["а", "б", "в"], номер = 2, запасная = "?" returns "б".

«Хвост через»

принимает части: список строки, разделитель: строка
возвращает строка

Test from the module: given части = ["автор", "Стругацкие"], разделитель = "=" returns "Стругацкие".

«Слова»

принимает текст: строка
возвращает список строки

Test from the module: given текст = "а б в" returns ["а", "б", "в"].

Other functions

No other library module and no example in the repository calls these functions. The functions above are called.

«Последняя строка»

принимает части: список строки
возвращает строка

Test from the module: given части = ["а", "б", "в"] returns "в".

«Хвост строк»

принимает части: список строки
возвращает список строки

Test from the module: given части = ["а", "б", "в"] returns ["б", "в"].

«Номер строки»

принимает части: список строки, искомая: строка
возвращает число

Test from the module: given части = ["а", "б", "в"], искомая = "б" returns 2.

«Дописать строку»

принимает части: список строки, новая: строка
возвращает список строки

Test from the module: given части = ["а", "б"], новая = "в" returns ["а", "б", "в"].

«Склеить»

принимает части: список строки
возвращает строка

Test from the module: given части = ["а", "б", "в"] returns "абв".

«Непустые»

принимает части: список строки
возвращает список строки

Test from the module: given части = ["", "автор=Стругацкие", ""] returns ["автор=Стругацкие"].

«Общее начало двух»

принимает первая: строка, вторая: строка
возвращает строка

Test from the module: given первая = "привет", вторая = "приказ" returns "при".

«Общее начало»

принимает части: список строки
возвращает строка

Test from the module: given части = ["полёт", "полка", "полено"] returns "пол".

Internal functions and types

Library modules declare no экспортирует list, so any function can be called. Internal here means by naming convention: a function «Шаг …» is a fold step, a type «Ход …» is a fold state, and so are functions that take or return such a type.

Show the list
«Шаг последней строки»: (ход: строка, часть: строка) → строка

Source: flang/stdlib/strlists.flang. All modules: Standard library.